summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
Diffstat (limited to 'graphics')
-rw-r--r--graphics/java/android/graphics/AvoidXfermode.java23
-rw-r--r--graphics/java/android/graphics/Bitmap.java14
-rw-r--r--graphics/java/android/graphics/BitmapFactory.java26
-rw-r--r--graphics/java/android/graphics/ImageFormat.java76
-rw-r--r--graphics/java/android/graphics/Path.java16
-rw-r--r--graphics/java/android/graphics/PixelFormat.java31
-rw-r--r--graphics/java/android/graphics/Typeface.java3
-rw-r--r--graphics/java/android/graphics/YuvImage.java240
-rw-r--r--graphics/java/android/graphics/drawable/NinePatchDrawable.java4
-rw-r--r--graphics/java/android/graphics/drawable/StateListDrawable.java5
-rw-r--r--graphics/java/android/renderscript/Allocation.java80
-rw-r--r--graphics/java/android/renderscript/BaseObj.java1
-rw-r--r--graphics/java/android/renderscript/Element.java553
-rw-r--r--graphics/java/android/renderscript/FieldPacker.java129
-rw-r--r--graphics/java/android/renderscript/Matrix2f.java58
-rw-r--r--graphics/java/android/renderscript/Matrix3f.java63
-rw-r--r--graphics/java/android/renderscript/Matrix4f.java (renamed from graphics/java/android/renderscript/Matrix.java)33
-rw-r--r--graphics/java/android/renderscript/Program.java144
-rw-r--r--graphics/java/android/renderscript/ProgramFragment.java167
-rw-r--r--graphics/java/android/renderscript/ProgramVertex.java91
-rw-r--r--graphics/java/android/renderscript/RSSurfaceView.java12
-rw-r--r--graphics/java/android/renderscript/RenderScript.java156
-rw-r--r--graphics/java/android/renderscript/RenderScriptGL.java127
-rw-r--r--graphics/java/android/renderscript/Sampler.java32
-rw-r--r--graphics/java/android/renderscript/SimpleMesh.java26
-rw-r--r--graphics/java/android/renderscript/Type.java11
-rw-r--r--graphics/java/android/renderscript/Vector2f.java37
-rw-r--r--graphics/java/android/renderscript/Vector3f.java38
-rw-r--r--graphics/java/android/renderscript/Vector4f.java38
-rw-r--r--graphics/jni/Android.mk3
-rw-r--r--graphics/jni/android_renderscript_RenderScript.cpp261
-rw-r--r--graphics/tests/graphicstests/Android.mk14
-rw-r--r--graphics/tests/graphicstests/AndroidManifest.xml37
-rw-r--r--graphics/tests/graphicstests/res/drawable/test128x96.pngbin0 -> 21474 bytes
-rw-r--r--graphics/tests/graphicstests/res/drawable/test16x12.pngbin0 -> 707 bytes
-rw-r--r--graphics/tests/graphicstests/res/drawable/test256x192.pngbin0 -> 78630 bytes
-rw-r--r--graphics/tests/graphicstests/res/drawable/test320x240.pngbin0 -> 39533 bytes
-rw-r--r--graphics/tests/graphicstests/res/drawable/test32x24.pngbin0 -> 1841 bytes
-rw-r--r--graphics/tests/graphicstests/res/drawable/test64x48.pngbin0 -> 6020 bytes
-rw-r--r--graphics/tests/graphicstests/src/android/graphics/BitmapTest.java232
-rw-r--r--graphics/tests/graphicstests/src/android/graphics/GraphicsPerformanceTests.java450
-rw-r--r--graphics/tests/graphicstests/src/android/graphics/GraphicsTests.java29
-rw-r--r--graphics/tests/graphicstests/src/android/graphics/ThreadBitmapTest.java47
-rw-r--r--graphics/tests/graphicstests/src/android/graphics/TypefaceTest.java91
44 files changed, 2618 insertions, 780 deletions
diff --git a/graphics/java/android/graphics/AvoidXfermode.java b/graphics/java/android/graphics/AvoidXfermode.java
index d7b0225..7e2722d 100644
--- a/graphics/java/android/graphics/AvoidXfermode.java
+++ b/graphics/java/android/graphics/AvoidXfermode.java
@@ -33,17 +33,20 @@ public class AvoidXfermode extends Xfermode {
final int nativeInt;
}
- /**
- * This xfermode will draw the src everywhere except on top of the opColor
- * or, depending on the Mode, draw only on top of the opColor.
+ /** This xfermode draws, or doesn't draw, based on the destination's
+ * distance from an op-color.
*
- * @param opColor The color to avoid (or to target depending on Mode). Note
- * that the alpha in opColor is ignored.
- * @param tolerance How closely we compare a pixel to the opColor.
- * 0 - only operate if exact match
- * 255 - maximum gradation (blending) based on how
- * similar the pixel is to our opColor (max tolerance)
- * @param mode If we should avoid or target the opColor
+ * There are two modes, and each mode interprets a tolerance value.
+ *
+ * Avoid: In this mode, drawing is allowed only on destination pixels that
+ * are different from the op-color.
+ * Tolerance near 0: avoid any colors even remotely similar to the op-color
+ * Tolerance near 255: avoid only colors nearly identical to the op-color
+
+ * Target: In this mode, drawing only occurs on destination pixels that
+ * are similar to the op-color
+ * Tolerance near 0: draw only on colors that are nearly identical to the op-color
+ * Tolerance near 255: draw on any colors even remotely similar to the op-color
*/
public AvoidXfermode(int opColor, int tolerance, Mode mode) {
if (tolerance < 0 || tolerance > 255) {
diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java
index 5aa88b0..7ca3741 100644
--- a/graphics/java/android/graphics/Bitmap.java
+++ b/graphics/java/android/graphics/Bitmap.java
@@ -972,6 +972,19 @@ public final class Bitmap implements Parcelable {
}
/**
+ * Given another bitmap, return true if it has the same dimensions, config,
+ * and pixel data as this bitmap. If any of those differ, return false.
+ * If other is null, return false.
+ *
+ * @hide (just needed internally right now)
+ */
+ public boolean sameAs(Bitmap other) {
+ return this == other ||
+ (other != null &&
+ nativeSameAs(mNativeBitmap, other.mNativeBitmap));
+ }
+
+ /**
* Rebuilds any caches associated with the bitmap that are used for
* drawing it. In the case of purgeable bitmaps, this call will attempt to
* ensure that the pixels have been decoded.
@@ -1042,6 +1055,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/BitmapFactory.java b/graphics/java/android/graphics/BitmapFactory.java
index f60a7be..2313f4c 100644
--- a/graphics/java/android/graphics/BitmapFactory.java
+++ b/graphics/java/android/graphics/BitmapFactory.java
@@ -532,7 +532,7 @@ public class BitmapFactory {
public static Bitmap decodeFileDescriptor(FileDescriptor fd, Rect outPadding, Options opts) {
try {
if (MemoryFile.isMemoryFile(fd)) {
- int mappedlength = MemoryFile.getMappedSize(fd);
+ int mappedlength = MemoryFile.getSize(fd);
MemoryFile file = new MemoryFile(fd, mappedlength, "r");
InputStream is = file.getInputStream();
Bitmap bm = decodeStream(is, outPadding, opts);
@@ -558,6 +558,30 @@ public class BitmapFactory {
return decodeFileDescriptor(fd, null, null);
}
+ /**
+ * Set the default config used for decoding bitmaps. This config is
+ * presented to the codec if the caller did not specify a preferred config
+ * in their call to decode...
+ *
+ * The default value is chosen by the system to best match the device's
+ * screen and memory constraints.
+ *
+ * @param config The preferred config for decoding bitmaps. If null, then
+ * a suitable default is chosen by the system.
+ *
+ * @hide - only called by the browser at the moment, but should be stable
+ * enough to expose if needed
+ */
+ public static void setDefaultConfig(Bitmap.Config config) {
+ if (config == null) {
+ // pick this for now, as historically it was our default.
+ // However, if we have a smarter algorithm, we can change this.
+ config = Bitmap.Config.RGB_565;
+ }
+ nativeSetDefaultConfig(config.nativeInt);
+ }
+
+ private static native void nativeSetDefaultConfig(int nativeConfig);
private static native Bitmap nativeDecodeStream(InputStream is, byte[] storage,
Rect padding, Options opts);
private static native Bitmap nativeDecodeFileDescriptor(FileDescriptor fd,
diff --git a/graphics/java/android/graphics/ImageFormat.java b/graphics/java/android/graphics/ImageFormat.java
new file mode 100644
index 0000000..f126374
--- /dev/null
+++ b/graphics/java/android/graphics/ImageFormat.java
@@ -0,0 +1,76 @@
+/*
+ * 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;
+
+public class ImageFormat
+{
+ /* these constants are chosen to be binary compatible with
+ * their previous location in PixelFormat.java */
+
+ public static final int UNKNOWN = 0;
+
+ /** RGB format used for pictures encoded as RGB_565
+ * see {@link android.hardware.Camera.Parameters#setPictureFormat(int)}.
+ */
+ public static final int RGB_565 = 4;
+
+ /**
+ * YCbCr formats, used for video. These are not necessarily supported
+ * by the hardware.
+ */
+ public static final int NV16 = 0x10;
+
+
+ /** YCrCb format used for images, which uses the NV21 encoding format.
+ * This is the default format for camera preview images, when not
+ * otherwise set with
+ * {@link android.hardware.Camera.Parameters#setPreviewFormat(int)}.
+ */
+ public static final int NV21 = 0x11;
+
+
+ /** YCbCr format used for images, which uses YUYV (YUY2) encoding format.
+ * This is an alternative format for camera preview images. Whether this
+ * format is supported by the camera hardware can be determined by
+ * {@link android.hardware.Camera.Parameters#getSupportedPreviewFormats()}.
+ */
+ public static final int YUY2 = 0x14;
+
+
+ /**
+ * Encoded formats. These are not necessarily supported by the hardware.
+ */
+ public static final int JPEG = 0x100;
+
+
+ /**
+ * Use this function to retrieve the number of bits per pixel of
+ * an ImageFormat.
+ * @param format
+ * @return the number of bits per pixel of the given format or -1 if the
+ * format doesn't exist or is not supported.
+ */
+ public static int getBitsPerPixel(int format) {
+ switch (format) {
+ case RGB_565: return 16;
+ case NV16: return 16;
+ case NV21: return 12;
+ case YUY2: return 16;
+ }
+ return -1;
+ }
+}
diff --git a/graphics/java/android/graphics/Path.java b/graphics/java/android/graphics/Path.java
index c3f63d7..281823a 100644
--- a/graphics/java/android/graphics/Path.java
+++ b/graphics/java/android/graphics/Path.java
@@ -153,16 +153,15 @@ public class Path {
}
/**
- * Compute the bounds of the path, and write the answer into bounds. If the
- * path contains 0 or 1 points, the bounds is set to (0,0,0,0)
+ * Compute the bounds of the control points of the path, and write the
+ * answer into bounds. If the path contains 0 or 1 points, the bounds is
+ * set to (0,0,0,0)
*
- * @param bounds Returns the computed bounds of the path
- * @param exact If true, return the exact (but slower) bounds, else return
- * just the bounds of all control points
+ * @param bounds Returns the computed bounds of the path's control points.
+ * @param exact This parameter is no longer used.
*/
public void computeBounds(RectF bounds, boolean exact) {
- // 1-exact, 0-fast correspond to the values in SkPath.h
- native_computeBounds(mNativePath, bounds, exact ? 1 : 0);
+ native_computeBounds(mNativePath, bounds);
}
/**
@@ -552,8 +551,7 @@ public class Path {
private static native void native_setFillType(int nPath, int ft);
private static native boolean native_isEmpty(int nPath);
private static native boolean native_isRect(int nPath, RectF rect);
- private static native void native_computeBounds(int nPath, RectF bounds,
- int btype);
+ private static native void native_computeBounds(int nPath, RectF bounds);
private static native void native_incReserve(int nPath, int extraPtCount);
private static native void native_moveTo(int nPath, float x, float y);
private static native void native_rMoveTo(int nPath, float dx, float dy);
diff --git a/graphics/java/android/graphics/PixelFormat.java b/graphics/java/android/graphics/PixelFormat.java
index c76cee7..182f14d 100644
--- a/graphics/java/android/graphics/PixelFormat.java
+++ b/graphics/java/android/graphics/PixelFormat.java
@@ -18,8 +18,7 @@ package android.graphics;
public class PixelFormat
{
- /* these constants need to match those
- in ui/PixelFormat.h & pixelflinger/format.h */
+ /* these constants need to match those in hardware/hardware.h */
public static final int UNKNOWN = 0;
@@ -46,30 +45,34 @@ public class PixelFormat
public static final int L_8 = 9;
public static final int LA_88 = 0xA;
public static final int RGB_332 = 0xB;
-
+
+
/**
- * YCbCr formats, used for video. These are not necessarily supported
- * by the hardware.
+ * @deprecated use {@link android.graphics.ImageFormat#NV16
+ * ImageFormat.NV16} instead.
*/
+ @Deprecated
public static final int YCbCr_422_SP= 0x10;
- /** YCbCr format used for images, which uses the NV21 encoding format.
- * This is the default format for camera preview images, when not
- * otherwise set with
- * {@link android.hardware.Camera.Parameters#setPreviewFormat(int)}.
+ /**
+ * @deprecated use {@link android.graphics.ImageFormat#NV21
+ * ImageFormat.NV21} instead.
*/
+ @Deprecated
public static final int YCbCr_420_SP= 0x11;
- /** YCbCr format used for images, which uses YUYV (YUY2) encoding format.
- * This is an alternative format for camera preview images. Whether this
- * format is supported by the camera hardware can be determined by
- * {@link android.hardware.Camera.Parameters#getSupportedPreviewFormats()}.
+ /**
+ * @deprecated use {@link android.graphics.ImageFormat#YUY2
+ * ImageFormat.YUY2} instead.
*/
+ @Deprecated
public static final int YCbCr_422_I = 0x14;
/**
- * Encoded formats. These are not necessarily supported by the hardware.
+ * @deprecated use {@link android.graphics.ImageFormat#JPEG
+ * ImageFormat.JPEG} instead.
*/
+ @Deprecated
public static final int JPEG = 0x100;
/*
diff --git a/graphics/java/android/graphics/Typeface.java b/graphics/java/android/graphics/Typeface.java
index f0d5a6a..bc92d3a 100644
--- a/graphics/java/android/graphics/Typeface.java
+++ b/graphics/java/android/graphics/Typeface.java
@@ -143,6 +143,9 @@ public class Typeface {
// don't allow clients to call this directly
private Typeface(int ni) {
+ if (0 == ni) {
+ throw new RuntimeException("native typeface cannot be made");
+ }
native_instance = ni;
}
diff --git a/graphics/java/android/graphics/YuvImage.java b/graphics/java/android/graphics/YuvImage.java
new file mode 100644
index 0000000..9368da6
--- /dev/null
+++ b/graphics/java/android/graphics/YuvImage.java
@@ -0,0 +1,240 @@
+/*
+ * 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 java.io.OutputStream;
+
+/**
+ * YuvImage contains YUV data and provides a method that compresses a region of
+ * the YUV data to a Jpeg. The YUV data should be provided as a single byte
+ * array irrespective of the number of image planes in it.
+ * Currently only ImageFormat.NV21 and ImageFormat.YUY2 are supported.
+ *
+ * To compress a rectangle region in the YUV data, users have to specify the
+ * region by left, top, width and height.
+ */
+public class YuvImage {
+
+ /**
+ * Number of bytes of temp storage we use for communicating between the
+ * native compressor and the java OutputStream.
+ */
+ private final static int WORKING_COMPRESS_STORAGE = 4096;
+
+ /**
+ * The YUV format as defined in {@link PixelFormat}.
+ */
+ private int mFormat;
+
+ /**
+ * The raw YUV data.
+ * In the case of more than one image plane, the image planes must be
+ * concatenated into a single byte array.
+ */
+ private byte[] mData;
+
+ /**
+ * The number of row bytes in each image plane.
+ */
+ private int[] mStrides;
+
+ /**
+ * The width of the image.
+ */
+ private int mWidth;
+
+ /**
+ * The height of the the image.
+ */
+ private int mHeight;
+
+ /**
+ * Construct an YuvImage.
+ *
+ * @param yuv The YUV data. In the case of more than one image plane, all the planes must be
+ * concatenated into a single byte array.
+ * @param format The YUV data format as defined in {@link PixelFormat}.
+ * @param width The width of the YuvImage.
+ * @param height The height of the YuvImage.
+ * @param strides (Optional) Row bytes of each image plane. If yuv contains padding, the stride
+ * of each image must be provided. If strides is null, the method assumes no
+ * padding and derives the row bytes by format and width itself.
+ * @throws IllegalArgumentException if format is not support; width or height <= 0; or yuv is
+ * null.
+ */
+ public YuvImage(byte[] yuv, int format, int width, int height, int[] strides) {
+ if (format != ImageFormat.NV21 &&
+ format != ImageFormat.YUY2) {
+ throw new IllegalArgumentException(
+ "only support ImageFormat.NV21 " +
+ "and ImageFormat.YUY2 for now");
+ }
+
+ if (width <= 0 || height <= 0) {
+ throw new IllegalArgumentException(
+ "width and height must large than 0");
+ }
+
+ if (yuv == null) {
+ throw new IllegalArgumentException("yuv cannot be null");
+ }
+
+ if (strides == null) {
+ mStrides = calculateStrides(width, format);
+ } else {
+ mStrides = strides;
+ }
+
+ mData = yuv;
+ mFormat = format;
+ mWidth = width;
+ mHeight = height;
+ }
+
+ /**
+ * Compress a rectangle region in the YuvImage to a jpeg.
+ * Only ImageFormat.NV21 and ImageFormat.YUY2
+ * are supported for now.
+ *
+ * @param rectangle The rectangle region to be compressed. The medthod checks if rectangle is
+ * inside the image. Also, the method modifies rectangle if the chroma pixels
+ * in it are not matched with the luma pixels in it.
+ * @param quality Hint to the compressor, 0-100. 0 meaning compress for
+ * small size, 100 meaning compress for max quality.
+ * @param stream OutputStream to write the compressed data.
+ * @return True if the compression is successful.
+ * @throws IllegalArgumentException if rectangle is invalid; quality is not within [0,
+ * 100]; or stream is null.
+ */
+ public boolean compressToJpeg(Rect rectangle, int quality, OutputStream stream) {
+ Rect wholeImage = new Rect(0, 0, mWidth, mHeight);
+ if (!wholeImage.contains(rectangle)) {
+ throw new IllegalArgumentException(
+ "rectangle is not inside the image");
+ }
+
+ if (quality < 0 || quality > 100) {
+ throw new IllegalArgumentException("quality must be 0..100");
+ }
+
+ if (stream == null) {
+ throw new IllegalArgumentException("stream cannot be null");
+ }
+
+ adjustRectangle(rectangle);
+ int[] offsets = calculateOffsets(rectangle.left, rectangle.top);
+
+ return nativeCompressToJpeg(mData, mFormat, rectangle.width(),
+ rectangle.height(), offsets, mStrides, quality, stream,
+ new byte[WORKING_COMPRESS_STORAGE]);
+ }
+
+
+ /**
+ * @return the YUV data.
+ */
+ public byte[] getYuvData() {
+ return mData;
+ }
+
+ /**
+ * @return the YUV format as defined in {@link PixelFormat}.
+ */
+ public int getYuvFormat() {
+ return mFormat;
+ }
+
+ /**
+ * @return the number of row bytes in each image plane.
+ */
+ public int[] getStrides() {
+ return mStrides;
+ }
+
+ /**
+ * @return the width of the image.
+ */
+ public int getWidth() {
+ return mWidth;
+ }
+
+ /**
+ * @return the height of the image.
+ */
+ public int getHeight() {
+ return mHeight;
+ }
+
+ int[] calculateOffsets(int left, int top) {
+ int[] offsets = null;
+ if (mFormat == ImageFormat.NV21) {
+ offsets = new int[] {top * mStrides[0] + left,
+ mHeight * mStrides[0] + top / 2 * mStrides[1]
+ + left / 2 * 2 };
+ return offsets;
+ }
+
+ if (mFormat == ImageFormat.YUY2) {
+ offsets = new int[] {top * mStrides[0] + left / 2 * 4};
+ return offsets;
+ }
+
+ return offsets;
+ }
+
+ private int[] calculateStrides(int width, int format) {
+ int[] strides = null;
+ if (format == ImageFormat.NV21) {
+ strides = new int[] {width, width};
+ return strides;
+ }
+
+ if (format == ImageFormat.YUY2) {
+ strides = new int[] {width * 2};
+ return strides;
+ }
+
+ return strides;
+ }
+
+ private void adjustRectangle(Rect rect) {
+ int width = rect.width();
+ int height = rect.height();
+ if (mFormat == ImageFormat.NV21) {
+ // Make sure left, top, width and height are all even.
+ width &= ~1;
+ height &= ~1;
+ rect.left &= ~1;
+ rect.top &= ~1;
+ rect.right = rect.left + width;
+ rect.bottom = rect.top + height;
+ }
+
+ if (mFormat == ImageFormat.YUY2) {
+ // Make sure left and width are both even.
+ width &= ~1;
+ rect.left &= ~1;
+ rect.right = rect.left + width;
+ }
+ }
+
+ //////////// native methods
+
+ private static native boolean nativeCompressToJpeg(byte[] oriYuv,
+ int format, int width, int height, int[] offsets, int[] strides,
+ int quality, OutputStream stream, byte[] tempStorage);
+}
diff --git a/graphics/java/android/graphics/drawable/NinePatchDrawable.java b/graphics/java/android/graphics/drawable/NinePatchDrawable.java
index 67a8015..bad94fb 100644
--- a/graphics/java/android/graphics/drawable/NinePatchDrawable.java
+++ b/graphics/java/android/graphics/drawable/NinePatchDrawable.java
@@ -81,7 +81,7 @@ public class NinePatchDrawable extends Drawable {
*/
@Deprecated
public NinePatchDrawable(NinePatch patch) {
- this(new NinePatchState(patch, null), null);
+ this(new NinePatchState(patch, new Rect()), null);
}
/**
@@ -89,7 +89,7 @@ public class NinePatchDrawable extends Drawable {
* based on the display metrics of the resources.
*/
public NinePatchDrawable(Resources res, NinePatch patch) {
- this(new NinePatchState(patch, null), res);
+ this(new NinePatchState(patch, new Rect()), res);
mNinePatchState.mTargetDensity = mTargetDensity;
}
diff --git a/graphics/java/android/graphics/drawable/StateListDrawable.java b/graphics/java/android/graphics/drawable/StateListDrawable.java
index b1d588e..b94df84 100644
--- a/graphics/java/android/graphics/drawable/StateListDrawable.java
+++ b/graphics/java/android/graphics/drawable/StateListDrawable.java
@@ -238,7 +238,10 @@ public class StateListDrawable extends DrawableContainer {
final int count = sets.length;
mStateListState.mStateSets = new int[count][];
for (int i = 0; i < count; i++) {
- mStateListState.mStateSets[i] = sets[i].clone();
+ final int[] set = sets[i];
+ if (set != null) {
+ mStateListState.mStateSets[i] = set.clone();
+ }
}
mMutated = true;
}
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java
index b6ac14a..17c0778 100644
--- a/graphics/java/android/renderscript/Allocation.java
+++ b/graphics/java/android/renderscript/Allocation.java
@@ -32,6 +32,7 @@ import android.util.TypedValue;
**/
public class Allocation extends BaseObj {
Type mType;
+ Bitmap mBitmap;
Allocation(int id, RenderScript rs, Type t) {
super(rs);
@@ -39,15 +40,22 @@ public class Allocation extends BaseObj {
mType = t;
}
+ public Type getType() {
+ return mType;
+ }
+
public void uploadToTexture(int baseMipLevel) {
mRS.validate();
- mRS.validateSurface();
- mRS.nAllocationUploadToTexture(mID, baseMipLevel);
+ mRS.nAllocationUploadToTexture(mID, false, baseMipLevel);
+ }
+
+ public void uploadToTexture(boolean genMips, int baseMipLevel) {
+ mRS.validate();
+ mRS.nAllocationUploadToTexture(mID, genMips, baseMipLevel);
}
public void uploadToBufferObject() {
mRS.validate();
- mRS.validateSurface();
mRS.nAllocationUploadToBufferObject(mID);
}
@@ -171,9 +179,10 @@ public class Allocation extends BaseObj {
public Adapter1D createAdapter1D() {
mRS.validate();
int id = mRS.nAdapter1DCreate();
- if (id != 0) {
- mRS.nAdapter1DBindAllocation(id, mID);
+ if(id == 0) {
+ throw new IllegalStateException("allocation failed.");
}
+ mRS.nAdapter1DBindAllocation(id, mID);
return new Adapter1D(id, mRS);
}
@@ -213,9 +222,10 @@ public class Allocation extends BaseObj {
public Adapter2D createAdapter2D() {
mRS.validate();
int id = mRS.nAdapter2DCreate();
- if (id != 0) {
- mRS.nAdapter2DBindAllocation(id, mID);
+ if(id == 0) {
+ throw new IllegalStateException("allocation failed.");
}
+ mRS.nAdapter2DBindAllocation(id, mID);
return new Adapter2D(id, mRS);
}
@@ -253,19 +263,68 @@ public class Allocation extends BaseObj {
return new Allocation(id, rs, t);
}
+ static private Element elementFromBitmap(RenderScript rs, Bitmap b) {
+ final Bitmap.Config bc = b.getConfig();
+ if (bc == Bitmap.Config.ALPHA_8) {
+ return Element.A_8(rs);
+ }
+ if (bc == Bitmap.Config.ARGB_4444) {
+ return Element.RGBA_4444(rs);
+ }
+ if (bc == Bitmap.Config.ARGB_8888) {
+ return Element.RGBA_8888(rs);
+ }
+ if (bc == Bitmap.Config.RGB_565) {
+ return Element.RGB_565(rs);
+ }
+ throw new IllegalStateException("Bad bitmap type.");
+ }
+
+ static private Type typeFromBitmap(RenderScript rs, Bitmap b) {
+ 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());
+ return tb.create();
+ }
+
static public Allocation createFromBitmap(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips)
throws IllegalArgumentException {
rs.validate();
+ Type t = typeFromBitmap(rs, b);
+
int id = rs.nAllocationCreateFromBitmap(dstFmt.mID, genMips, b);
- return new Allocation(id, rs, null);
+ if(id == 0) {
+ throw new IllegalStateException("Load failed.");
+ }
+ return new Allocation(id, rs, t);
+ }
+
+ static public Allocation createBitmapRef(RenderScript rs, Bitmap b)
+ throws IllegalArgumentException {
+
+ rs.validate();
+ Type t = typeFromBitmap(rs, b);
+
+ int id = rs.nAllocationCreateBitmapRef(t.getID(), b);
+ if(id == 0) {
+ throw new IllegalStateException("Load failed.");
+ }
+
+ Allocation a = new Allocation(id, rs, t);
+ a.mBitmap = b;
+ return a;
}
- static public Allocation createFromBitmapBoxed(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips)
+ static Allocation createFromBitmapBoxed(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips)
throws IllegalArgumentException {
rs.validate();
int id = rs.nAllocationCreateFromBitmapBoxed(dstFmt.mID, genMips, b);
+ if(id == 0) {
+ throw new IllegalStateException("Load failed.");
+ }
return new Allocation(id, rs, null);
}
@@ -282,6 +341,9 @@ public class Allocation extends BaseObj {
int allocationId = rs.nAllocationCreateFromAssetStream(dstFmt.mID, genMips,
asset);
+ if(allocationId == 0) {
+ throw new IllegalStateException("Load failed.");
+ }
return new Allocation(allocationId, rs, null);
} catch (Exception e) {
// Ignore
diff --git a/graphics/java/android/renderscript/BaseObj.java b/graphics/java/android/renderscript/BaseObj.java
index e802ec5..002fc78 100644
--- a/graphics/java/android/renderscript/BaseObj.java
+++ b/graphics/java/android/renderscript/BaseObj.java
@@ -25,6 +25,7 @@ import android.util.Log;
class BaseObj {
BaseObj(RenderScript rs) {
+ rs.validate();
mRS = rs;
mID = 0;
mDestroyed = false;
diff --git a/graphics/java/android/renderscript/Element.java b/graphics/java/android/renderscript/Element.java
index ee9b098..10ef05a 100644
--- a/graphics/java/android/renderscript/Element.java
+++ b/graphics/java/android/renderscript/Element.java
@@ -24,259 +24,220 @@ import java.lang.reflect.Field;
**/
public class Element extends BaseObj {
int mSize;
- Entry[] mEntries;
+ Element[] mElements;
+ String[] mElementNames;
- int getSizeBytes() {
- return mSize;
- }
- int getComponentCount() {
- return mEntries.length;
- }
- Element.DataType getComponentDataType(int num) {
- return mEntries[num].mType;
- }
- Element.DataKind getComponentDataKind(int num) {
- return mEntries[num].mKind;
- }
- boolean getComponentIsNormalized(int num) {
- return mEntries[num].mIsNormalized;
- }
- int getComponentBits(int num) {
- return mEntries[num].mBits;
- }
- String getComponentName(int num) {
- return mEntries[num].mName;
+ DataType mType;
+ DataKind mKind;
+ boolean mNormalized;
+ int mVectorSize;
+
+ int getSizeBytes() {return mSize;}
+
+ public enum DataType {
+ //FLOAT_16 (1, 2),
+ FLOAT_32 (2, 4),
+ //FLOAT_64 (3, 8),
+ SIGNED_8 (4, 1),
+ SIGNED_16 (5, 2),
+ SIGNED_32 (6, 4),
+ //SIGNED_64 (7, 8),
+ UNSIGNED_8 (8, 1),
+ UNSIGNED_16 (9, 2),
+ UNSIGNED_32 (10, 4),
+ //UNSIGNED_64 (11, 8),
+
+ UNSIGNED_5_6_5 (12, 2),
+ UNSIGNED_5_5_5_1 (13, 2),
+ UNSIGNED_4_4_4_4 (14, 2),
+
+ RS_ELEMENT (15, 4),
+ RS_TYPE (16, 4),
+ RS_ALLOCATION (17, 4),
+ RS_SAMPLER (18, 4),
+ RS_SCRIPT (19, 4),
+ RS_MESH (20, 4),
+ RS_PROGRAM_FRAGMENT (21, 4),
+ RS_PROGRAM_VERTEX (22, 4),
+ RS_PROGRAM_RASTER (23, 4),
+ RS_PROGRAM_STORE (24, 4);
+
+ int mID;
+ int mSize;
+ DataType(int id, int size) {
+ mID = id;
+ mSize = size;
+ }
}
- static class Entry {
- //Element mElement;
- Element.DataType mType;
- Element.DataKind mKind;
- boolean mIsNormalized;
- int mBits;
- String mName;
-
- //Entry(Element e, int bits) {
- //mElement = e;
- //int mBits = bits;
- //}
-
- Entry(DataType dt, DataKind dk, boolean isNorm, int bits, String name) {
- mType = dt;
- mKind = dk;
- mIsNormalized = isNorm;
- mBits = bits;
- mName = name;
+ public enum DataKind {
+ USER (0),
+ COLOR (1),
+ POSITION (2),
+ TEXTURE (3),
+ NORMAL (4),
+ INDEX (5),
+ POINT_SIZE(6),
+
+ PIXEL_L (7),
+ PIXEL_A (8),
+ PIXEL_LA (9),
+ PIXEL_RGB (10),
+ PIXEL_RGBA (11);
+
+ int mID;
+ DataKind(int id) {
+ mID = id;
}
}
public static Element USER_U8(RenderScript rs) {
if(rs.mElement_USER_U8 == null) {
- rs.mElement_USER_U8 = new Element(rs, 1);
- rs.mElement_USER_U8.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.USER, false, 8, null);
- rs.mElement_USER_U8.init();
+ rs.mElement_USER_U8 = createUser(rs, DataType.UNSIGNED_8);
}
return rs.mElement_USER_U8;
}
public static Element USER_I8(RenderScript rs) {
if(rs.mElement_USER_I8 == null) {
- rs.mElement_USER_I8 = new Element(rs, 1);
- rs.mElement_USER_I8.mEntries[0] = new Entry(DataType.SIGNED, DataKind.USER, false, 8, null);
- rs.mElement_USER_I8.init();
+ rs.mElement_USER_I8 = createUser(rs, DataType.SIGNED_8);
}
return rs.mElement_USER_I8;
}
- public static Element USER_U16(RenderScript rs) {
- if(rs.mElement_USER_U16 == null) {
- rs.mElement_USER_U16 = new Element(rs, 1);
- rs.mElement_USER_U16.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.USER, false, 16, null);
- rs.mElement_USER_U16.init();
- }
- return rs.mElement_USER_U16;
- }
-
- public static Element USER_I16(RenderScript rs) {
- if(rs.mElement_USER_I16 == null) {
- rs.mElement_USER_I16 = new Element(rs, 1);
- rs.mElement_USER_I16.mEntries[0] = new Entry(DataType.SIGNED, DataKind.USER, false, 16, null);
- rs.mElement_USER_I16.init();
- }
- return rs.mElement_USER_I16;
- }
-
public static Element USER_U32(RenderScript rs) {
if(rs.mElement_USER_U32 == null) {
- rs.mElement_USER_U32 = new Element(rs, 1);
- rs.mElement_USER_U32.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.USER, false, 32, null);
- rs.mElement_USER_U32.init();
+ rs.mElement_USER_U32 = createUser(rs, DataType.UNSIGNED_32);
}
return rs.mElement_USER_U32;
}
public static Element USER_I32(RenderScript rs) {
if(rs.mElement_USER_I32 == null) {
- rs.mElement_USER_I32 = new Element(rs, 1);
- rs.mElement_USER_I32.mEntries[0] = new Entry(DataType.SIGNED, DataKind.USER, false, 32, null);
- rs.mElement_USER_I32.init();
+ rs.mElement_USER_I32 = createUser(rs, DataType.SIGNED_32);
}
return rs.mElement_USER_I32;
}
public static Element USER_F32(RenderScript rs) {
- if(rs.mElement_USER_FLOAT == null) {
- rs.mElement_USER_FLOAT = new Element(rs, 1);
- rs.mElement_USER_FLOAT.mEntries[0] = new Entry(DataType.FLOAT, DataKind.USER, false, 32, null);
- rs.mElement_USER_FLOAT.init();
+ if(rs.mElement_USER_F32 == null) {
+ rs.mElement_USER_F32 = createUser(rs, DataType.FLOAT_32);
}
- return rs.mElement_USER_FLOAT;
+ return rs.mElement_USER_F32;
}
public static Element A_8(RenderScript rs) {
if(rs.mElement_A_8 == null) {
- rs.mElement_A_8 = new Element(rs, 1);
- rs.mElement_A_8.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.ALPHA, true, 8, "a");
- rs.mElement_A_8.init();
+ rs.mElement_A_8 = createPixel(rs, DataType.UNSIGNED_8, DataKind.PIXEL_A);
}
return rs.mElement_A_8;
}
public static Element RGB_565(RenderScript rs) {
if(rs.mElement_RGB_565 == null) {
- rs.mElement_RGB_565 = new Element(rs, 3);
- rs.mElement_RGB_565.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 5, "r");
- rs.mElement_RGB_565.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 6, "g");
- rs.mElement_RGB_565.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 5, "b");
- rs.mElement_RGB_565.init();
+ rs.mElement_RGB_565 = createPixel(rs, DataType.UNSIGNED_5_6_5, DataKind.PIXEL_RGB);
}
return rs.mElement_RGB_565;
}
public static Element RGB_888(RenderScript rs) {
if(rs.mElement_RGB_888 == null) {
- rs.mElement_RGB_888 = new Element(rs, 3);
- rs.mElement_RGB_888.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 8, "r");
- rs.mElement_RGB_888.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 8, "g");
- rs.mElement_RGB_888.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 8, "b");
- rs.mElement_RGB_888.init();
+ rs.mElement_RGB_888 = createPixel(rs, DataType.UNSIGNED_8, DataKind.PIXEL_RGB);
}
return rs.mElement_RGB_888;
}
public static Element RGBA_5551(RenderScript rs) {
if(rs.mElement_RGBA_5551 == null) {
- rs.mElement_RGBA_5551 = new Element(rs, 4);
- rs.mElement_RGBA_5551.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 5, "r");
- rs.mElement_RGBA_5551.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 5, "g");
- rs.mElement_RGBA_5551.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 5, "b");
- rs.mElement_RGBA_5551.mEntries[3] = new Entry(DataType.UNSIGNED, DataKind.ALPHA, true, 1, "a");
- rs.mElement_RGBA_5551.init();
+ rs.mElement_RGBA_5551 = createPixel(rs, DataType.UNSIGNED_5_5_5_1, DataKind.PIXEL_RGBA);
}
return rs.mElement_RGBA_5551;
}
public static Element RGBA_4444(RenderScript rs) {
if(rs.mElement_RGBA_4444 == null) {
- rs.mElement_RGBA_4444 = new Element(rs, 4);
- rs.mElement_RGBA_4444.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 4, "r");
- rs.mElement_RGBA_4444.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 4, "g");
- rs.mElement_RGBA_4444.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 4, "b");
- rs.mElement_RGBA_4444.mEntries[3] = new Entry(DataType.UNSIGNED, DataKind.ALPHA, true, 4, "a");
- rs.mElement_RGBA_4444.init();
+ rs.mElement_RGBA_4444 = createPixel(rs, DataType.UNSIGNED_4_4_4_4, DataKind.PIXEL_RGBA);
}
return rs.mElement_RGBA_4444;
}
public static Element RGBA_8888(RenderScript rs) {
if(rs.mElement_RGBA_8888 == null) {
- rs.mElement_RGBA_8888 = new Element(rs, 4);
- rs.mElement_RGBA_8888.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 8, "r");
- rs.mElement_RGBA_8888.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 8, "g");
- rs.mElement_RGBA_8888.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 8, "b");
- rs.mElement_RGBA_8888.mEntries[3] = new Entry(DataType.UNSIGNED, DataKind.ALPHA, true, 8, "a");
- rs.mElement_RGBA_8888.init();
+ rs.mElement_RGBA_8888 = createPixel(rs, DataType.UNSIGNED_8, DataKind.PIXEL_RGBA);
}
return rs.mElement_RGBA_8888;
}
public static Element INDEX_16(RenderScript rs) {
if(rs.mElement_INDEX_16 == null) {
- rs.mElement_INDEX_16 = new Element(rs, 1);
- rs.mElement_INDEX_16.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.INDEX, false, 16, "index");
- rs.mElement_INDEX_16.init();
+ rs.mElement_INDEX_16 = createIndex(rs);
}
return rs.mElement_INDEX_16;
}
- public static Element XY_F32(RenderScript rs) {
- if(rs.mElement_XY_F32 == null) {
- rs.mElement_XY_F32 = new Element(rs, 2);
- rs.mElement_XY_F32.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.X, false, 32, "x");
- rs.mElement_XY_F32.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.Y, false, 32, "y");
- rs.mElement_XY_F32.init();
+ public static Element ATTRIB_POSITION_2(RenderScript rs) {
+ if(rs.mElement_POSITION_2 == null) {
+ rs.mElement_POSITION_2 = createAttrib(rs, DataType.FLOAT_32, DataKind.POSITION, 2);
}
- return rs.mElement_XY_F32;
+ return rs.mElement_POSITION_2;
}
- public static Element XYZ_F32(RenderScript rs) {
- if(rs.mElement_XYZ_F32 == null) {
- rs.mElement_XYZ_F32 = new Element(rs, 3);
- rs.mElement_XYZ_F32.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.X, false, 32, "x");
- rs.mElement_XYZ_F32.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.Y, false, 32, "y");
- rs.mElement_XYZ_F32.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.Z, false, 32, "z");
- rs.mElement_XYZ_F32.init();
+ public static Element ATTRIB_POSITION_3(RenderScript rs) {
+ if(rs.mElement_POSITION_3 == null) {
+ rs.mElement_POSITION_3 = createAttrib(rs, DataType.FLOAT_32, DataKind.POSITION, 3);
}
- return rs.mElement_XYZ_F32;
+ return rs.mElement_POSITION_3;
}
- static void initPredefined(RenderScript rs) {
- rs.nInitElements(A_8(rs).mID, RGBA_4444(rs).mID, RGBA_8888(rs).mID, RGB_565(rs).mID);
+ public static Element ATTRIB_TEXTURE_2(RenderScript rs) {
+ if(rs.mElement_TEXTURE_2 == null) {
+ rs.mElement_TEXTURE_2 = createAttrib(rs, DataType.FLOAT_32, DataKind.TEXTURE, 2);
+ }
+ return rs.mElement_TEXTURE_2;
}
- public enum DataType {
- FLOAT (0),
- UNSIGNED (1),
- SIGNED (2);
-
- int mID;
- DataType(int id) {
- mID = id;
+ public static Element ATTRIB_NORMAL_3(RenderScript rs) {
+ if(rs.mElement_NORMAL_3 == null) {
+ rs.mElement_NORMAL_3 = createAttrib(rs, DataType.FLOAT_32, DataKind.NORMAL, 3);
}
+ return rs.mElement_NORMAL_3;
}
- public enum DataKind {
- USER (0),
- RED (1),
- GREEN (2),
- BLUE (3),
- ALPHA (4),
- LUMINANCE (5),
- INTENSITY (6),
- X (7),
- Y (8),
- Z (9),
- W (10),
- S (11),
- T (12),
- Q (13),
- R (14),
- NX (15),
- NY (16),
- NZ (17),
- INDEX (18),
- POINT_SIZE(19);
+ public static Element ATTRIB_COLOR_U8_4(RenderScript rs) {
+ if(rs.mElement_COLOR_U8_4 == null) {
+ rs.mElement_COLOR_U8_4 = createAttrib(rs, DataType.UNSIGNED_8, DataKind.COLOR, 4);
+ }
+ return rs.mElement_COLOR_U8_4;
+ }
- int mID;
- DataKind(int id) {
- mID = id;
+ public static Element ATTRIB_COLOR_F32_4(RenderScript rs) {
+ if(rs.mElement_COLOR_F32_4 == null) {
+ rs.mElement_COLOR_F32_4 = createAttrib(rs, DataType.FLOAT_32, DataKind.COLOR, 4);
}
+ return rs.mElement_COLOR_F32_4;
}
- Element(RenderScript rs, int count) {
+ Element(RenderScript rs, Element[] e, String[] n) {
super(rs);
mSize = 0;
- mEntries = new Entry[count];
+ mElements = e;
+ mElementNames = n;
+ int[] ids = new int[mElements.length];
+ for (int ct = 0; ct < mElements.length; ct++ ) {
+ mSize += mElements[ct].mSize;
+ ids[ct] = mElements[ct].mID;
+ }
+ mID = rs.nElementCreate2(ids, mElementNames);
+ }
+
+ Element(RenderScript rs, DataType dt, DataKind dk, boolean norm, int size) {
+ super(rs);
+ mSize = dt.mSize * size;
+ mType = dt;
+ mKind = dk;
+ mNormalized = norm;
+ mVectorSize = size;
+ mID = rs.nElementCreate(dt.mID, dk.mID, norm, size);
}
public void destroy() throws IllegalStateException {
@@ -291,13 +252,13 @@ public class Element extends BaseObj {
for(Field f: fields) {
Class fc = f.getType();
if(fc == int.class) {
- b.add(Element.DataType.SIGNED, Element.DataKind.USER, false, 32, f.getName());
+ b.add(createUser(rs, DataType.SIGNED_32), f.getName());
} else if(fc == short.class) {
- b.add(Element.DataType.SIGNED, Element.DataKind.USER, false, 16, f.getName());
+ b.add(createUser(rs, DataType.SIGNED_16), f.getName());
} else if(fc == byte.class) {
- b.add(Element.DataType.SIGNED, Element.DataKind.USER, false, 8, f.getName());
+ b.add(createUser(rs, DataType.SIGNED_8), f.getName());
} else if(fc == float.class) {
- b.add(Element.DataType.FLOAT, Element.DataKind.USER, false, 32, f.getName());
+ b.add(createUser(rs, DataType.FLOAT_32), f.getName());
} else {
throw new IllegalArgumentException("Unkown field type");
}
@@ -305,193 +266,157 @@ public class Element extends BaseObj {
return b.create();
}
- static synchronized void internalCreate(RenderScript rs, Element e) {
- rs.nElementBegin();
- int bits = 0;
- for (int ct=0; ct < e.mEntries.length; ct++) {
- Entry en = e.mEntries[ct];
- //if(en.mElement != null) {
- //rs.nElementAdd(en.mElement.mID);
- //} else
- {
- rs.nElementAdd(en.mKind.mID, en.mType.mID, en.mIsNormalized, en.mBits, en.mName);
- bits += en.mBits;
- }
- }
- e.mID = rs.nElementCreate();
- e.mSize = (bits + 7) >> 3;
- }
- void init() {
- mRS.validate();
- internalCreate(mRS, this);
+ /////////////////////////////////////////
+ public static Element createUser(RenderScript rs, DataType dt) {
+ return new Element(rs, dt, DataKind.USER, false, 1);
}
-
- public static class Builder {
- RenderScript mRS;
- Entry[] mEntries;
- int mEntryCount;
-
- public Builder(RenderScript rs) {
- mRS = rs;
- mEntryCount = 0;
- mEntries = new Entry[8];
- }
-
- void addEntry(Entry e) {
- if(mEntries.length >= mEntryCount) {
- Entry[] en = new Entry[mEntryCount + 8];
- System.arraycopy(mEntries, 0, en, 0, mEntries.length);
- mEntries = en;
- }
- mEntries[mEntryCount] = e;
- mEntryCount++;
+ public static Element createVector(RenderScript rs, DataType dt, int size) {
+ if (size < 2 || size > 4) {
+ throw new IllegalArgumentException("Bad size");
}
+ return new Element(rs, dt, DataKind.USER, false, size);
+ }
- //public Builder add(Element e) throws IllegalArgumentException {
- //Entry en = new Entry(e, e.mSize * 8);
- //addEntry(en);
- //return this;
- //}
+ public static Element createIndex(RenderScript rs) {
+ return new Element(rs, DataType.UNSIGNED_16, DataKind.INDEX, false, 1);
+ }
- public Builder add(Element.DataType dt, Element.DataKind dk, boolean isNormalized, int bits, String name) {
- Entry en = new Entry(dt, dk, isNormalized, bits, name);
- addEntry(en);
- return this;
+ public static Element createAttrib(RenderScript rs, DataType dt, DataKind dk, int size) {
+ if (!(dt == DataType.FLOAT_32 ||
+ dt == DataType.UNSIGNED_8 ||
+ dt == DataType.UNSIGNED_16 ||
+ dt == DataType.UNSIGNED_32 ||
+ dt == DataType.SIGNED_8 ||
+ dt == DataType.SIGNED_16 ||
+ dt == DataType.SIGNED_32)) {
+ throw new IllegalArgumentException("Unsupported DataType");
}
- public Builder add(Element.DataType dt, Element.DataKind dk, boolean isNormalized, int bits) {
- add(dt, dk, isNormalized, bits, null);
- return this;
+ if (!(dk == DataKind.COLOR ||
+ dk == DataKind.POSITION ||
+ dk == DataKind.TEXTURE ||
+ dk == DataKind.NORMAL ||
+ dk == DataKind.POINT_SIZE ||
+ dk == DataKind.USER)) {
+ throw new IllegalArgumentException("Unsupported DataKind");
}
- public Builder addFloat(Element.DataKind dk) {
- add(DataType.FLOAT, dk, false, 32, null);
- return this;
+ if (dk == DataKind.COLOR &&
+ ((dt != DataType.FLOAT_32 && dt != DataType.UNSIGNED_8) ||
+ size < 3 || size > 4)) {
+ throw new IllegalArgumentException("Bad combo");
}
-
- public Builder addFloat(Element.DataKind dk, String name) {
- add(DataType.FLOAT, dk, false, 32, name);
- return this;
+ if (dk == DataKind.POSITION && (size < 1 || size > 4)) {
+ throw new IllegalArgumentException("Bad combo");
}
-
- public Builder addFloatXY() {
- add(DataType.FLOAT, DataKind.X, false, 32, null);
- add(DataType.FLOAT, DataKind.Y, false, 32, null);
- return this;
+ if (dk == DataKind.TEXTURE &&
+ (dt != DataType.FLOAT_32 || size < 1 || size > 4)) {
+ throw new IllegalArgumentException("Bad combo");
}
-
- public Builder addFloatXY(String prefix) {
- add(DataType.FLOAT, DataKind.X, false, 32, prefix + "x");
- add(DataType.FLOAT, DataKind.Y, false, 32, prefix + "y");
- return this;
+ if (dk == DataKind.NORMAL &&
+ (dt != DataType.FLOAT_32 || size != 3)) {
+ throw new IllegalArgumentException("Bad combo");
}
-
- public Builder addFloatXYZ() {
- add(DataType.FLOAT, DataKind.X, false, 32, null);
- add(DataType.FLOAT, DataKind.Y, false, 32, null);
- add(DataType.FLOAT, DataKind.Z, false, 32, null);
- return this;
+ if (dk == DataKind.POINT_SIZE &&
+ (dt != DataType.FLOAT_32 || size != 1)) {
+ throw new IllegalArgumentException("Bad combo");
}
- public Builder addFloatXYZ(String prefix) {
- add(DataType.FLOAT, DataKind.X, false, 32, prefix + "x");
- add(DataType.FLOAT, DataKind.Y, false, 32, prefix + "y");
- add(DataType.FLOAT, DataKind.Z, false, 32, prefix + "z");
- return this;
+ boolean norm = false;
+ if (dk == DataKind.COLOR && dt == DataType.UNSIGNED_8) {
+ norm = true;
}
- public Builder addFloatST() {
- add(DataType.FLOAT, DataKind.S, false, 32, null);
- add(DataType.FLOAT, DataKind.T, false, 32, null);
- return this;
- }
+ return new Element(rs, dt, dk, norm, size);
+ }
- public Builder addFloatST(String prefix) {
- add(DataType.FLOAT, DataKind.S, false, 32, prefix + "s");
- add(DataType.FLOAT, DataKind.T, false, 32, prefix + "t");
- return this;
+ public static Element createPixel(RenderScript rs, DataType dt, DataKind dk) {
+ if (!(dk == DataKind.PIXEL_L ||
+ dk == DataKind.PIXEL_A ||
+ dk == DataKind.PIXEL_LA ||
+ dk == DataKind.PIXEL_RGB ||
+ dk == DataKind.PIXEL_RGBA)) {
+ throw new IllegalArgumentException("Unsupported DataKind");
}
-
- public Builder addFloatNorm() {
- add(DataType.FLOAT, DataKind.NX, false, 32, null);
- add(DataType.FLOAT, DataKind.NY, false, 32, null);
- add(DataType.FLOAT, DataKind.NZ, false, 32, null);
- return this;
+ if (!(dt == DataType.UNSIGNED_8 ||
+ dt == DataType.UNSIGNED_5_6_5 ||
+ dt == DataType.UNSIGNED_4_4_4_4 ||
+ dt == DataType.UNSIGNED_5_5_5_1)) {
+ throw new IllegalArgumentException("Unsupported DataType");
}
-
- public Builder addFloatNorm(String prefix) {
- add(DataType.FLOAT, DataKind.NX, false, 32, prefix + "nx");
- add(DataType.FLOAT, DataKind.NY, false, 32, prefix + "ny");
- add(DataType.FLOAT, DataKind.NZ, false, 32, prefix + "nz");
- return this;
+ if (dt == DataType.UNSIGNED_5_6_5 && dk != DataKind.PIXEL_RGB) {
+ throw new IllegalArgumentException("Bad kind and type combo");
}
-
- public Builder addFloatPointSize() {
- add(DataType.FLOAT, DataKind.POINT_SIZE, false, 32, null);
- return this;
+ if (dt == DataType.UNSIGNED_5_5_5_1 && dk != DataKind.PIXEL_RGBA) {
+ throw new IllegalArgumentException("Bad kind and type combo");
}
-
- public Builder addFloatPointSize(String prefix) {
- add(DataType.FLOAT, DataKind.POINT_SIZE, false, 32, prefix + "pointSize");
- return this;
+ if (dt == DataType.UNSIGNED_4_4_4_4 && dk != DataKind.PIXEL_RGBA) {
+ throw new IllegalArgumentException("Bad kind and type combo");
}
- public Builder addFloatRGB() {
- add(DataType.FLOAT, DataKind.RED, false, 32, null);
- add(DataType.FLOAT, DataKind.GREEN, false, 32, null);
- add(DataType.FLOAT, DataKind.BLUE, false, 32, null);
- return this;
+ int size = 1;
+ if (dk == DataKind.PIXEL_LA) {
+ size = 2;
}
-
- public Builder addFloatRGB(String prefix) {
- add(DataType.FLOAT, DataKind.RED, false, 32, prefix + "r");
- add(DataType.FLOAT, DataKind.GREEN, false, 32, prefix + "g");
- add(DataType.FLOAT, DataKind.BLUE, false, 32, prefix + "b");
- return this;
+ if (dk == DataKind.PIXEL_RGB) {
+ size = 3;
}
-
- public Builder addFloatRGBA() {
- add(DataType.FLOAT, DataKind.RED, false, 32, null);
- add(DataType.FLOAT, DataKind.GREEN, false, 32, null);
- add(DataType.FLOAT, DataKind.BLUE, false, 32, null);
- add(DataType.FLOAT, DataKind.ALPHA, false, 32, null);
- return this;
+ if (dk == DataKind.PIXEL_RGBA) {
+ size = 4;
}
- public Builder addFloatRGBA(String prefix) {
- add(DataType.FLOAT, DataKind.RED, false, 32, prefix + "r");
- add(DataType.FLOAT, DataKind.GREEN, false, 32, prefix + "g");
- add(DataType.FLOAT, DataKind.BLUE, false, 32, prefix + "b");
- add(DataType.FLOAT, DataKind.ALPHA, false, 32, prefix + "a");
- return this;
- }
+ return new Element(rs, dt, dk, true, size);
+ }
- public Builder addUNorm8RGBA() {
- add(DataType.UNSIGNED, DataKind.RED, true, 8, null);
- add(DataType.UNSIGNED, DataKind.GREEN, true, 8, null);
- add(DataType.UNSIGNED, DataKind.BLUE, true, 8, null);
- add(DataType.UNSIGNED, DataKind.ALPHA, true, 8, null);
- return this;
- }
+ public static class Builder {
+ RenderScript mRS;
+ Element[] mElements;
+ String[] mElementNames;
+ int mCount;
- public Builder addUNorm8RGBA(String prefix) {
- add(DataType.UNSIGNED, DataKind.RED, true, 8, prefix + "r");
- add(DataType.UNSIGNED, DataKind.GREEN, true, 8, prefix + "g");
- add(DataType.UNSIGNED, DataKind.BLUE, true, 8, prefix + "b");
- add(DataType.UNSIGNED, DataKind.ALPHA, true, 8, prefix + "a");
- return this;
+ public Builder(RenderScript rs) {
+ mRS = rs;
+ mCount = 0;
+ mElements = new Element[8];
+ mElementNames = new String[8];
+ }
+
+ public void add(Element element, String name) {
+ if(mCount == mElements.length) {
+ Element[] e = new Element[mCount + 8];
+ String[] s = new String[mCount + 8];
+ System.arraycopy(mElements, 0, e, 0, mCount);
+ System.arraycopy(mElementNames, 0, s, 0, mCount);
+ mElements = e;
+ mElementNames = s;
+ }
+ mElements[mCount] = element;
+ mElementNames[mCount] = name;
+ mCount++;
}
public Element create() {
mRS.validate();
- Element e = new Element(mRS, mEntryCount);
- java.lang.System.arraycopy(mEntries, 0, e.mEntries, 0, mEntryCount);
- e.init();
- return e;
+ Element[] ein = new Element[mCount];
+ String[] sin = new String[mCount];
+ java.lang.System.arraycopy(mElements, 0, ein, 0, mCount);
+ java.lang.System.arraycopy(mElementNames, 0, sin, 0, mCount);
+ return new Element(mRS, ein, sin);
}
}
+ static void initPredefined(RenderScript rs) {
+ int a8 = rs.nElementCreate(DataType.UNSIGNED_8.mID,
+ DataKind.PIXEL_A.mID, true, 1);
+ int rgba4444 = rs.nElementCreate(DataType.UNSIGNED_4_4_4_4.mID,
+ DataKind.PIXEL_RGBA.mID, true, 4);
+ int rgba8888 = rs.nElementCreate(DataType.UNSIGNED_8.mID,
+ DataKind.PIXEL_RGBA.mID, true, 4);
+ int rgb565 = rs.nElementCreate(DataType.UNSIGNED_5_6_5.mID,
+ DataKind.PIXEL_RGB.mID, true, 3);
+ rs.nInitElements(a8, rgba4444, rgba8888, rgb565);
+ }
}
diff --git a/graphics/java/android/renderscript/FieldPacker.java b/graphics/java/android/renderscript/FieldPacker.java
new file mode 100644
index 0000000..b26e47d
--- /dev/null
+++ b/graphics/java/android/renderscript/FieldPacker.java
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.renderscript;
+
+
+/**
+ * @hide
+ *
+ **/
+public class FieldPacker {
+ public FieldPacker(int len) {
+ mPos = 0;
+ mData = new byte[len];
+ }
+
+ public void align(int v) {
+ while ((mPos & (v - 1)) != 0) {
+ mData[mPos++] = 0;
+ }
+ }
+
+ void reset() {
+ mPos = 0;
+ }
+
+ void addI8(byte v) {
+ mData[mPos++] = v;
+ }
+
+ void addI16(short v) {
+ align(2);
+ mData[mPos++] = (byte)(v & 0xff);
+ mData[mPos++] = (byte)(v >> 8);
+ }
+
+ void addI32(int v) {
+ align(4);
+ mData[mPos++] = (byte)(v & 0xff);
+ mData[mPos++] = (byte)((v >> 8) & 0xff);
+ mData[mPos++] = (byte)((v >> 16) & 0xff);
+ mData[mPos++] = (byte)((v >> 24) & 0xff);
+ }
+
+ void addI64(long v) {
+ align(8);
+ mData[mPos++] = (byte)(v & 0xff);
+ mData[mPos++] = (byte)((v >> 8) & 0xff);
+ mData[mPos++] = (byte)((v >> 16) & 0xff);
+ mData[mPos++] = (byte)((v >> 24) & 0xff);
+ mData[mPos++] = (byte)((v >> 32) & 0xff);
+ mData[mPos++] = (byte)((v >> 40) & 0xff);
+ mData[mPos++] = (byte)((v >> 48) & 0xff);
+ mData[mPos++] = (byte)((v >> 56) & 0xff);
+ }
+
+ void addU8(short v) {
+ if ((v < 0) || (v > 0xff)) {
+ throw new IllegalArgumentException("Saving value out of range for type");
+ }
+ mData[mPos++] = (byte)v;
+ }
+
+ void addU16(int v) {
+ if ((v < 0) || (v > 0xffff)) {
+ throw new IllegalArgumentException("Saving value out of range for type");
+ }
+ align(2);
+ mData[mPos++] = (byte)(v & 0xff);
+ mData[mPos++] = (byte)(v >> 8);
+ }
+
+ void addU32(long v) {
+ if ((v < 0) || (v > 0xffffffff)) {
+ throw new IllegalArgumentException("Saving value out of range for type");
+ }
+ align(4);
+ mData[mPos++] = (byte)(v & 0xff);
+ mData[mPos++] = (byte)((v >> 8) & 0xff);
+ mData[mPos++] = (byte)((v >> 16) & 0xff);
+ mData[mPos++] = (byte)((v >> 24) & 0xff);
+ }
+
+ void addU64(long v) {
+ if (v < 0) {
+ throw new IllegalArgumentException("Saving value out of range for type");
+ }
+ align(8);
+ mData[mPos++] = (byte)(v & 0xff);
+ mData[mPos++] = (byte)((v >> 8) & 0xff);
+ mData[mPos++] = (byte)((v >> 16) & 0xff);
+ mData[mPos++] = (byte)((v >> 24) & 0xff);
+ mData[mPos++] = (byte)((v >> 32) & 0xff);
+ mData[mPos++] = (byte)((v >> 40) & 0xff);
+ mData[mPos++] = (byte)((v >> 48) & 0xff);
+ mData[mPos++] = (byte)((v >> 56) & 0xff);
+ }
+
+ void addF32(float v) {
+ addI32(Float.floatToRawIntBits(v));
+ }
+
+ void addF64(float v) {
+ addI64(Double.doubleToRawLongBits(v));
+ }
+
+ final byte[] getData() {
+ return mData;
+ }
+
+ private final byte mData[];
+ private int mPos;
+
+}
+
+
diff --git a/graphics/java/android/renderscript/Matrix2f.java b/graphics/java/android/renderscript/Matrix2f.java
new file mode 100644
index 0000000..4b5e61b
--- /dev/null
+++ b/graphics/java/android/renderscript/Matrix2f.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.renderscript;
+
+import java.lang.Math;
+import android.util.Log;
+
+
+/**
+ * @hide
+ *
+ **/
+public class Matrix2f {
+
+ public Matrix2f() {
+ mMat = new float[4];
+ loadIdentity();
+ }
+
+ public float get(int i, int j) {
+ return mMat[i*2 + j];
+ }
+
+ public void set(int i, int j, float v) {
+ mMat[i*2 + j] = v;
+ }
+
+ public void loadIdentity() {
+ mMat[0] = 1;
+ mMat[1] = 0;
+
+ mMat[2] = 0;
+ mMat[3] = 1;
+ }
+
+ public void load(Matrix2f src) {
+ System.arraycopy(mMat, 0, src, 0, 4);
+ }
+
+ final float[] mMat;
+}
+
+
+
diff --git a/graphics/java/android/renderscript/Matrix3f.java b/graphics/java/android/renderscript/Matrix3f.java
new file mode 100644
index 0000000..19d7b43
--- /dev/null
+++ b/graphics/java/android/renderscript/Matrix3f.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.renderscript;
+
+import java.lang.Math;
+import android.util.Log;
+
+
+/**
+ * @hide
+ *
+ **/
+public class Matrix3f {
+
+ public Matrix3f() {
+ mMat = new float[9];
+ loadIdentity();
+ }
+
+ public float get(int i, int j) {
+ return mMat[i*3 + j];
+ }
+
+ public void set(int i, int j, float v) {
+ mMat[i*3 + j] = v;
+ }
+
+ public void loadIdentity() {
+ mMat[0] = 1;
+ mMat[1] = 0;
+ mMat[2] = 0;
+
+ mMat[3] = 0;
+ mMat[4] = 1;
+ mMat[5] = 0;
+
+ mMat[6] = 0;
+ mMat[7] = 0;
+ mMat[8] = 1;
+ }
+
+ public void load(Matrix3f src) {
+ System.arraycopy(mMat, 0, src, 0, 9);
+ }
+
+ final float[] mMat;
+}
+
+
diff --git a/graphics/java/android/renderscript/Matrix.java b/graphics/java/android/renderscript/Matrix4f.java
index a266d6b..ebd5bde 100644
--- a/graphics/java/android/renderscript/Matrix.java
+++ b/graphics/java/android/renderscript/Matrix4f.java
@@ -24,9 +24,9 @@ import android.util.Log;
* @hide
*
**/
-public class Matrix {
+public class Matrix4f {
- public Matrix() {
+ public Matrix4f() {
mMat = new float[16];
loadIdentity();
}
@@ -49,7 +49,7 @@ public class Matrix {
mMat[5] = 1;
mMat[6] = 0;
mMat[7] = 0;
-
+
mMat[8] = 0;
mMat[9] = 0;
mMat[10] = 1;
@@ -61,8 +61,8 @@ public class Matrix {
mMat[15] = 1;
}
- public void load(Matrix src) {
- mMat = src.mMat;
+ public void load(Matrix4f src) {
+ System.arraycopy(mMat, 0, src, 0, 16);
}
public void loadRotate(float rot, float x, float y, float z) {
@@ -77,7 +77,7 @@ public class Matrix {
rot *= (float)(java.lang.Math.PI / 180.0f);
c = (float)java.lang.Math.cos(rot);
s = (float)java.lang.Math.sin(rot);
-
+
float len = (float)java.lang.Math.sqrt(x*x + y*y + z*z);
if (!(len != 1)) {
float recipLen = 1.f / len;
@@ -91,7 +91,7 @@ public class Matrix {
float zx = z * x;
float xs = x * s;
float ys = y * s;
- float zs = z * s;
+ float zs = z * s;
mMat[ 0] = x*x*nc + c;
mMat[ 4] = xy*nc - zs;
mMat[ 8] = zx*nc + ys;
@@ -109,7 +109,7 @@ public class Matrix {
mMat[5] = y;
mMat[10] = z;
}
-
+
public void loadTranslate(float x, float y, float z) {
loadIdentity();
mMat[12] = x;
@@ -117,7 +117,7 @@ public class Matrix {
mMat[14] = z;
}
- public void loadMultiply(Matrix lhs, Matrix rhs) {
+ public void loadMultiply(Matrix4f lhs, Matrix4f rhs) {
for (int i=0 ; i<4 ; i++) {
float ri0 = 0;
float ri1 = 0;
@@ -159,31 +159,28 @@ public class Matrix {
mMat[15]= 0;
}
- public void multiply(Matrix rhs) {
- Matrix tmp = new Matrix();
+ public void multiply(Matrix4f rhs) {
+ Matrix4f tmp = new Matrix4f();
tmp.loadMultiply(this, rhs);
load(tmp);
}
public void rotate(float rot, float x, float y, float z) {
- Matrix tmp = new Matrix();
+ Matrix4f tmp = new Matrix4f();
tmp.loadRotate(rot, x, y, z);
multiply(tmp);
}
public void scale(float x, float y, float z) {
- Matrix tmp = new Matrix();
+ Matrix4f tmp = new Matrix4f();
tmp.loadScale(x, y, z);
multiply(tmp);
}
public void translate(float x, float y, float z) {
- Matrix tmp = new Matrix();
+ Matrix4f tmp = new Matrix4f();
tmp.loadTranslate(x, y, z);
multiply(tmp);
}
-
-
- float[] mMat;
-
+ final float[] mMat;
}
diff --git a/graphics/java/android/renderscript/Program.java b/graphics/java/android/renderscript/Program.java
new file mode 100644
index 0000000..1614ec5
--- /dev/null
+++ b/graphics/java/android/renderscript/Program.java
@@ -0,0 +1,144 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.renderscript;
+
+
+import android.util.Config;
+import android.util.Log;
+
+
+/**
+ * @hide
+ *
+ **/
+public class Program extends BaseObj {
+ public static final int MAX_INPUT = 8;
+ public static final int MAX_OUTPUT = 8;
+ public static final int MAX_CONSTANT = 8;
+ public static final int MAX_TEXTURE = 8;
+
+ Element mInputs[];
+ Element mOutputs[];
+ Type mConstants[];
+ int mTextureCount;
+ String mShader;
+
+ Program(int id, RenderScript rs) {
+ super(rs);
+ mID = id;
+ }
+
+ public void bindConstants(Allocation a, int slot) {
+ mRS.nProgramBindConstants(mID, slot, a.mID);
+ }
+
+ public void bindTexture(Allocation va, int slot)
+ throws IllegalArgumentException {
+ mRS.validate();
+ if((slot < 0) || (slot >= mTextureCount)) {
+ throw new IllegalArgumentException("Slot ID out of range.");
+ }
+
+ mRS.nProgramBindTexture(mID, slot, va.mID);
+ }
+
+ public void bindSampler(Sampler vs, int slot)
+ throws IllegalArgumentException {
+ mRS.validate();
+ if((slot < 0) || (slot >= mTextureCount)) {
+ throw new IllegalArgumentException("Slot ID out of range.");
+ }
+
+ mRS.nProgramBindSampler(mID, slot, vs.mID);
+ }
+
+
+ public static class BaseProgramBuilder {
+ RenderScript mRS;
+ Element mInputs[];
+ Element mOutputs[];
+ Type mConstants[];
+ Type mTextures[];
+ int mInputCount;
+ int mOutputCount;
+ int mConstantCount;
+ int mTextureCount;
+ String mShader;
+
+
+ protected BaseProgramBuilder(RenderScript rs) {
+ mRS = rs;
+ mInputs = new Element[MAX_INPUT];
+ mOutputs = new Element[MAX_OUTPUT];
+ mConstants = new Type[MAX_CONSTANT];
+ mInputCount = 0;
+ mOutputCount = 0;
+ mConstantCount = 0;
+ mTextureCount = 0;
+ }
+
+ public void setShader(String s) {
+ mShader = s;
+ }
+
+ public void addInput(Element e) throws IllegalStateException {
+ // Should check for consistant and non-conflicting names...
+ if(mInputCount >= MAX_INPUT) {
+ throw new IllegalArgumentException("Max input count exceeded.");
+ }
+ mInputs[mInputCount++] = e;
+ }
+
+ public void addOutput(Element e) throws IllegalStateException {
+ // Should check for consistant and non-conflicting names...
+ if(mOutputCount >= MAX_OUTPUT) {
+ throw new IllegalArgumentException("Max output count exceeded.");
+ }
+ mOutputs[mOutputCount++] = e;
+ }
+
+ public int addConstant(Type t) throws IllegalStateException {
+ // Should check for consistant and non-conflicting names...
+ if(mConstantCount >= MAX_CONSTANT) {
+ throw new IllegalArgumentException("Max input count exceeded.");
+ }
+ mConstants[mConstantCount] = t;
+ return mConstantCount++;
+ }
+
+ public void setTextureCount(int count) throws IllegalArgumentException {
+ // Should check for consistant and non-conflicting names...
+ if(count >= MAX_CONSTANT) {
+ throw new IllegalArgumentException("Max texture count exceeded.");
+ }
+ mTextureCount = count;
+ }
+
+ protected void initProgram(Program p) {
+ p.mInputs = new Element[mInputCount];
+ System.arraycopy(mInputs, 0, p.mInputs, 0, mInputCount);
+ p.mOutputs = new Element[mOutputCount];
+ System.arraycopy(mOutputs, 0, p.mOutputs, 0, mOutputCount);
+ p.mConstants = new Type[mConstantCount];
+ System.arraycopy(mConstants, 0, p.mConstants, 0, mConstantCount);
+ p.mTextureCount = mTextureCount;
+ }
+ }
+
+}
+
+
diff --git a/graphics/java/android/renderscript/ProgramFragment.java b/graphics/java/android/renderscript/ProgramFragment.java
index 1a72578..5e04f0c 100644
--- a/graphics/java/android/renderscript/ProgramFragment.java
+++ b/graphics/java/android/renderscript/ProgramFragment.java
@@ -25,134 +25,115 @@ import android.util.Log;
* @hide
*
**/
-public class ProgramFragment extends BaseObj {
- public static final int MAX_SLOT = 2;
-
- public enum EnvMode {
- REPLACE (0),
- MODULATE (1),
- DECAL (2);
-
- int mID;
- EnvMode(int id) {
- mID = id;
- }
- }
-
-
+public class ProgramFragment extends Program {
ProgramFragment(int id, RenderScript rs) {
- super(rs);
- mID = id;
+ super(id, rs);
}
- public void bindTexture(Allocation va, int slot)
- throws IllegalArgumentException {
- mRS.validate();
- if((slot < 0) || (slot >= MAX_SLOT)) {
- throw new IllegalArgumentException("Slot ID out of range.");
+ public static class ShaderBuilder extends BaseProgramBuilder {
+ public ShaderBuilder(RenderScript rs) {
+ super(rs);
}
- mRS.nProgramFragmentBindTexture(mID, slot, va.mID);
- }
+ public ProgramFragment create() {
+ mRS.validate();
+ int[] tmp = new int[(mInputCount + mOutputCount + mConstantCount + 1) * 2];
+ int idx = 0;
- public void bindSampler(Sampler vs, int slot)
- throws IllegalArgumentException {
- mRS.validate();
- if((slot < 0) || (slot >= MAX_SLOT)) {
- throw new IllegalArgumentException("Slot ID out of range.");
- }
+ for (int i=0; i < mInputCount; i++) {
+ tmp[idx++] = 0;
+ tmp[idx++] = mInputs[i].mID;
+ }
+ for (int i=0; i < mOutputCount; i++) {
+ tmp[idx++] = 1;
+ tmp[idx++] = mOutputs[i].mID;
+ }
+ for (int i=0; i < mConstantCount; i++) {
+ tmp[idx++] = 2;
+ tmp[idx++] = mConstants[i].mID;
+ }
+ tmp[idx++] = 3;
+ tmp[idx++] = mTextureCount;
- mRS.nProgramFragmentBindSampler(mID, slot, vs.mID);
+ int id = mRS.nProgramFragmentCreate2(mShader, tmp);
+ ProgramFragment pf = new ProgramFragment(id, mRS);
+ initProgram(pf);
+ return pf;
+ }
}
-
public static class Builder {
+ public static final int MAX_TEXTURE = 2;
RenderScript mRS;
- Element mIn;
- Element mOut;
boolean mPointSpriteEnable;
- private class Slot {
- Type mType;
- EnvMode mEnv;
- boolean mTexEnable;
+ public enum EnvMode {
+ REPLACE (1),
+ MODULATE (2),
+ DECAL (3);
- Slot() {
- mTexEnable = false;
+ int mID;
+ EnvMode(int id) {
+ mID = id;
}
}
- Slot[] mSlots;
- public Builder(RenderScript rs, Element in, Element out) {
- mRS = rs;
- mIn = in;
- mOut = out;
- mSlots = new Slot[MAX_SLOT];
- mPointSpriteEnable = false;
- for(int ct=0; ct < MAX_SLOT; ct++) {
- mSlots[ct] = new Slot();
- }
- }
+ public enum Format {
+ ALPHA (1),
+ LUMINANCE_ALPHA (2),
+ RGB (3),
+ RGBA (4);
- public void setType(int slot, Type t)
- throws IllegalArgumentException {
- if((slot < 0) || (slot >= MAX_SLOT)) {
- throw new IllegalArgumentException("Slot ID out of range.");
+ int mID;
+ Format(int id) {
+ mID = id;
}
-
- mSlots[slot].mType = t;
}
- public void setTexEnable(boolean enable, int slot)
- throws IllegalArgumentException {
- if((slot < 0) || (slot >= MAX_SLOT)) {
- throw new IllegalArgumentException("Slot ID out of range.");
+ private class Slot {
+ EnvMode env;
+ Format format;
+ Slot(EnvMode _env, Format _fmt) {
+ env = _env;
+ format = _fmt;
}
+ }
+ Slot[] mSlots;
- mSlots[slot].mTexEnable = enable;
+ public Builder(RenderScript rs) {
+ mRS = rs;
+ mSlots = new Slot[MAX_TEXTURE];
+ mPointSpriteEnable = false;
}
- public void setTexEnvMode(EnvMode env, int slot)
+ public void setTexture(EnvMode env, Format fmt, int slot)
throws IllegalArgumentException {
- if((slot < 0) || (slot >= MAX_SLOT)) {
- throw new IllegalArgumentException("Slot ID out of range.");
+ if((slot < 0) || (slot >= MAX_TEXTURE)) {
+ throw new IllegalArgumentException("MAX_TEXTURE exceeded.");
}
-
- mSlots[slot].mEnv = env;
+ mSlots[slot] = new Slot(env, fmt);
}
public void setPointSpriteTexCoordinateReplacement(boolean enable) {
mPointSpriteEnable = enable;
}
- static synchronized ProgramFragment internalCreate(RenderScript rs, Builder b) {
- int inID = 0;
- int outID = 0;
- if (b.mIn != null) {
- inID = b.mIn.mID;
- }
- if (b.mOut != null) {
- outID = b.mOut.mID;
- }
- rs.nProgramFragmentBegin(inID, outID, b.mPointSpriteEnable);
- for(int ct=0; ct < MAX_SLOT; ct++) {
- if(b.mSlots[ct].mTexEnable) {
- Slot s = b.mSlots[ct];
- int typeID = 0;
- if(s.mType != null) {
- typeID = s.mType.mID;
- }
- rs.nProgramFragmentSetSlot(ct, true, s.mEnv.mID, typeID);
- }
- }
-
- int id = rs.nProgramFragmentCreate();
- return new ProgramFragment(id, rs);
- }
-
public ProgramFragment create() {
mRS.validate();
- return internalCreate(mRS, this);
+ int[] tmp = new int[MAX_TEXTURE * 2 + 1];
+ if (mSlots[0] != null) {
+ tmp[0] = mSlots[0].env.mID;
+ tmp[1] = mSlots[0].format.mID;
+ }
+ if (mSlots[1] != null) {
+ tmp[2] = mSlots[1].env.mID;
+ tmp[3] = mSlots[1].format.mID;
+ }
+ tmp[4] = mPointSpriteEnable ? 1 : 0;
+ int id = mRS.nProgramFragmentCreate(tmp);
+ ProgramFragment pf = new ProgramFragment(id, mRS);
+ pf.mTextureCount = MAX_TEXTURE;
+ return pf;
}
}
}
diff --git a/graphics/java/android/renderscript/ProgramVertex.java b/graphics/java/android/renderscript/ProgramVertex.java
index ba97d5b..1b155d7 100644
--- a/graphics/java/android/renderscript/ProgramVertex.java
+++ b/graphics/java/android/renderscript/ProgramVertex.java
@@ -25,72 +25,67 @@ import android.util.Log;
* @hide
*
**/
-public class ProgramVertex extends BaseObj {
+public class ProgramVertex extends Program {
public static final int MAX_LIGHT = 8;
+
ProgramVertex(int id, RenderScript rs) {
- super(rs);
- mID = id;
+ super(id, rs);
}
public void bindAllocation(MatrixAllocation va) {
mRS.validate();
- mRS.nProgramVertexBindAllocation(mID, va.mAlloc.mID);
+ bindConstants(va.mAlloc, 0);
}
public static class Builder {
RenderScript mRS;
- Element mIn;
- Element mOut;
- Light[] mLights;
- int mLightCount;
boolean mTextureMatrixEnable;
-
public Builder(RenderScript rs, Element in, Element out) {
mRS = rs;
- mIn = in;
- mOut = out;
- mLights = new Light[MAX_LIGHT];
- mLightCount = 0;
}
public void setTextureMatrixEnable(boolean enable) {
mTextureMatrixEnable = enable;
}
- public void addLight(Light l) throws IllegalStateException {
- if(mLightCount >= MAX_LIGHT) {
- throw new IllegalArgumentException("Max light count exceeded.");
- }
- mLights[mLightCount] = l;
- mLightCount++;
+ public ProgramVertex create() {
+ int id = mRS.nProgramVertexCreate(mTextureMatrixEnable);
+ return new ProgramVertex(id, mRS);
}
+ }
+ public static class ShaderBuilder extends BaseProgramBuilder {
+ public ShaderBuilder(RenderScript rs) {
+ super(rs);
+ }
+ public ProgramVertex create() {
+ mRS.validate();
+ int[] tmp = new int[(mInputCount + mOutputCount + mConstantCount +1) * 2];
+ int idx = 0;
- static synchronized ProgramVertex internalCreate(RenderScript rs, Builder b) {
- int inID = 0;
- int outID = 0;
- if (b.mIn != null) {
- inID = b.mIn.mID;
+ for (int i=0; i < mInputCount; i++) {
+ tmp[idx++] = 0;
+ tmp[idx++] = mInputs[i].mID;
}
- if (b.mOut != null) {
- outID = b.mOut.mID;
+ for (int i=0; i < mOutputCount; i++) {
+ tmp[idx++] = 1;
+ tmp[idx++] = mOutputs[i].mID;
}
- rs.nProgramVertexBegin(inID, outID);
- for(int ct=0; ct < b.mLightCount; ct++) {
- rs.nProgramVertexAddLight(b.mLights[ct].mID);
+ for (int i=0; i < mConstantCount; i++) {
+ tmp[idx++] = 2;
+ tmp[idx++] = mConstants[i].mID;
}
- rs.nProgramVertexSetTextureMatrixEnable(b.mTextureMatrixEnable);
- int id = rs.nProgramVertexCreate();
- return new ProgramVertex(id, rs);
- }
+ tmp[idx++] = 3;
+ tmp[idx++] = mTextureCount;
- public ProgramVertex create() {
- mRS.validate();
- return internalCreate(mRS, this);
+ int id = mRS.nProgramVertexCreate2(mShader, tmp);
+ ProgramVertex pv = new ProgramVertex(id, mRS);
+ initProgram(pv);
+ return pv;
}
}
@@ -101,18 +96,18 @@ public class ProgramVertex extends BaseObj {
static final int PROJECTION_OFFSET = 16;
static final int TEXTURE_OFFSET = 32;
- Matrix mModel;
- Matrix mProjection;
- Matrix mTexture;
+ Matrix4f mModel;
+ Matrix4f mProjection;
+ Matrix4f mTexture;
public Allocation mAlloc;
public MatrixAllocation(RenderScript rs) {
- mModel = new Matrix();
- mProjection = new Matrix();
- mTexture = new Matrix();
+ mModel = new Matrix4f();
+ mProjection = new Matrix4f();
+ mTexture = new Matrix4f();
- mAlloc = Allocation.createSized(rs, Element.USER_F32(rs), 48);
+ 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);
@@ -123,17 +118,17 @@ public class ProgramVertex extends BaseObj {
mAlloc = null;
}
- public void loadModelview(Matrix m) {
+ public void loadModelview(Matrix4f m) {
mModel = m;
mAlloc.subData1D(MODELVIEW_OFFSET, 16, m.mMat);
}
- public void loadProjection(Matrix m) {
+ public void loadProjection(Matrix4f m) {
mProjection = m;
mAlloc.subData1D(PROJECTION_OFFSET, 16, m.mMat);
}
- public void loadTexture(Matrix m) {
+ public void loadTexture(Matrix4f m) {
mTexture = m;
mAlloc.subData1D(TEXTURE_OFFSET, 16, m.mMat);
}
@@ -157,8 +152,8 @@ public class ProgramVertex extends BaseObj {
public void setupProjectionNormalized(int w, int h) {
// range -1,1 in the narrow axis at z = 0.
- Matrix m1 = new Matrix();
- Matrix m2 = new Matrix();
+ Matrix4f m1 = new Matrix4f();
+ Matrix4f m2 = new Matrix4f();
if(w > h) {
float aspect = ((float)w) / h;
diff --git a/graphics/java/android/renderscript/RSSurfaceView.java b/graphics/java/android/renderscript/RSSurfaceView.java
index ad1bb54..f05e84c 100644
--- a/graphics/java/android/renderscript/RSSurfaceView.java
+++ b/graphics/java/android/renderscript/RSSurfaceView.java
@@ -36,7 +36,7 @@ import android.view.SurfaceView;
**/
public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
private SurfaceHolder mSurfaceHolder;
- private RenderScript mRS;
+ private RenderScriptGL mRS;
/**
* Standard View constructor. In order to render something, you
@@ -146,13 +146,13 @@ public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback
// ----------------------------------------------------------------------
- public RenderScript createRenderScript(boolean useDepth, boolean forceSW) {
+ public RenderScriptGL createRenderScript(boolean useDepth, boolean forceSW) {
Log.v(RenderScript.LOG_TAG, "createRenderScript");
- mRS = new RenderScript(useDepth, forceSW);
+ mRS = new RenderScriptGL(useDepth, forceSW);
return mRS;
}
- public RenderScript createRenderScript(boolean useDepth) {
+ public RenderScriptGL createRenderScript(boolean useDepth) {
return createRenderScript(useDepth, false);
}
@@ -161,5 +161,9 @@ public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback
mRS.destroy();
mRS = null;
}
+
+ public void createRenderScript(RenderScriptGL rs) {
+ mRS = rs;
+ }
}
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java
index 0d8b675..a935243 100644
--- a/graphics/java/android/renderscript/RenderScript.java
+++ b/graphics/java/android/renderscript/RenderScript.java
@@ -31,11 +31,9 @@ import android.view.Surface;
**/
public class RenderScript {
static final String LOG_TAG = "RenderScript_jni";
- private static final boolean DEBUG = false;
+ protected static final boolean DEBUG = false;
@SuppressWarnings({"UnusedDeclaration", "deprecation"})
- private static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV;
- int mWidth;
- int mHeight;
+ protected static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV;
@@ -44,8 +42,8 @@ public class RenderScript {
* field offsets.
*/
@SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"})
- private static boolean sInitialized;
- native private static void _nInit();
+ protected static boolean sInitialized;
+ native protected static void _nInit();
static {
@@ -64,7 +62,8 @@ public class RenderScript {
native int nDeviceCreate();
native void nDeviceDestroy(int dev);
native void nDeviceSetConfig(int dev, int param, int value);
- native int nContextCreate(int dev, int ver, boolean useDepth);
+ native int nContextCreateGL(int dev, int ver, boolean useDepth);
+ native int nContextCreate(int dev, int ver);
native void nContextDestroy(int con);
native void nContextSetSurface(int w, int h, Surface sur);
native void nContextSetPriority(int p);
@@ -76,8 +75,6 @@ public class RenderScript {
native void nContextBindProgramFragment(int pf);
native void nContextBindProgramVertex(int pf);
native void nContextBindProgramRaster(int pr);
- native void nContextAddDefineI32(String name, int value);
- native void nContextAddDefineF(String name, float value);
native void nContextPause();
native void nContextResume();
native int nContextGetMessage(int[] data, boolean wait);
@@ -89,9 +86,9 @@ public class RenderScript {
native void nObjDestroyOOB(int id);
native int nFileOpen(byte[] name);
- native void nElementBegin();
- native void nElementAdd(int kind, int type, boolean norm, int bits, String s);
- native int nElementCreate();
+
+ native int nElementCreate(int type, int kind, boolean norm, int vecSize);
+ native int nElementCreate2(int[] elements, String[] names);
native void nTypeBegin(int elementID);
native void nTypeAdd(int dim, int val);
@@ -101,10 +98,11 @@ public class RenderScript {
native int nAllocationCreateTyped(int type);
native int nAllocationCreateFromBitmap(int dstFmt, boolean genMips, Bitmap bmp);
+ native int nAllocationCreateBitmapRef(int type, Bitmap bmp);
native int nAllocationCreateFromBitmapBoxed(int dstFmt, boolean genMips, Bitmap bmp);
native int nAllocationCreateFromAssetStream(int dstFmt, boolean genMips, int assetStream);
- native void nAllocationUploadToTexture(int alloc, int baseMioLevel);
+ native void nAllocationUploadToTexture(int alloc, boolean genMips, int baseMioLevel);
native void nAllocationUploadToBufferObject(int alloc);
native void nAllocationSubData1D(int id, int off, int count, int[] d, int sizeBytes);
@@ -167,17 +165,15 @@ public class RenderScript {
native void nProgramRasterSetLineWidth(int pr, float v);
native void nProgramRasterSetPointSize(int pr, float v);
- native void nProgramFragmentBegin(int in, int out, boolean pointSpriteEnable);
- native void nProgramFragmentBindTexture(int vpf, int slot, int a);
- native void nProgramFragmentBindSampler(int vpf, int slot, int s);
- native void nProgramFragmentSetSlot(int slot, boolean enable, int env, int vt);
- native int nProgramFragmentCreate();
+ native void nProgramBindConstants(int pv, int slot, int mID);
+ native void nProgramBindTexture(int vpf, int slot, int a);
+ native void nProgramBindSampler(int vpf, int slot, int s);
+
+ native int nProgramFragmentCreate(int[] params);
+ native int nProgramFragmentCreate2(String shader, int[] params);
- native void nProgramVertexBindAllocation(int pv, int mID);
- native void nProgramVertexBegin(int inID, int outID);
- native void nProgramVertexSetTextureMatrixEnable(boolean enable);
- native void nProgramVertexAddLight(int id);
- native int nProgramVertexCreate();
+ native int nProgramVertexCreate(boolean texMat);
+ native int nProgramVertexCreate2(String shader, int[] params);
native void nLightBegin();
native void nLightSetIsMono(boolean isMono);
@@ -194,12 +190,10 @@ public class RenderScript {
native void nAnimationAdd(float time, float[] attribs);
native int nAnimationCreate();
- private int mDev;
- private int mContext;
+ protected int mDev;
+ protected int mContext;
@SuppressWarnings({"FieldCanBeLocal"})
- private Surface mSurface;
- private MessageThread mMessageThread;
-
+ protected MessageThread mMessageThread;
Element mElement_USER_U8;
Element mElement_USER_I8;
@@ -207,7 +201,7 @@ public class RenderScript {
Element mElement_USER_I16;
Element mElement_USER_U32;
Element mElement_USER_I32;
- Element mElement_USER_FLOAT;
+ Element mElement_USER_F32;
Element mElement_A_8;
Element mElement_RGB_565;
@@ -217,9 +211,12 @@ public class RenderScript {
Element mElement_RGBA_8888;
Element mElement_INDEX_16;
- Element mElement_XY_F32;
- Element mElement_XYZ_F32;
-
+ Element mElement_POSITION_2;
+ Element mElement_POSITION_3;
+ Element mElement_TEXTURE_2;
+ Element mElement_NORMAL_3;
+ Element mElement_COLOR_U8_4;
+ Element mElement_COLOR_F32_4;
///////////////////////////////////////////////////////////////////////////////////
//
@@ -248,17 +245,12 @@ public class RenderScript {
}
}
- void validateSurface() {
- if (mSurface == null) {
- throw new IllegalStateException("Uploading data to GL with no surface.");
- }
- }
-
public void contextSetPriority(Priority p) {
+ validate();
nContextSetPriority(p.mID);
}
- private static class MessageThread extends Thread {
+ protected static class MessageThread extends Thread {
RenderScript mRS;
boolean mRun = true;
@@ -296,32 +288,27 @@ public class RenderScript {
}
}
- public RenderScript(boolean useDepth, boolean forceSW) {
- mSurface = null;
- mWidth = 0;
- mHeight = 0;
- mDev = nDeviceCreate();
- if(forceSW) {
- nDeviceSetConfig(mDev, 0, 1);
- }
- mContext = nContextCreate(mDev, 0, useDepth);
- Element.initPredefined(this);
- mMessageThread = new MessageThread(this);
- mMessageThread.start();
+ protected RenderScript() {
}
- public void contextSetSurface(int w, int h, Surface sur) {
- mSurface = sur;
- mWidth = w;
- mHeight = h;
- nContextSetSurface(w, h, mSurface);
+ public static RenderScript create() {
+ RenderScript rs = new RenderScript();
+
+ rs.mDev = rs.nDeviceCreate();
+ rs.mContext = rs.nContextCreate(rs.mDev, 0);
+ rs.mMessageThread = new MessageThread(rs);
+ rs.mMessageThread.start();
+ Element.initPredefined(rs);
+ return rs;
}
public void contextDump(int bits) {
+ validate();
nContextDump(bits);
}
public void destroy() {
+ validate();
nContextDeinitToClient();
mMessageThread.mRun = false;
@@ -336,70 +323,15 @@ public class RenderScript {
return mContext != 0;
}
- void pause() {
- nContextPause();
- }
-
- void resume() {
- nContextResume();
- }
-
- //////////////////////////////////////////////////////////////////////////////////
- // File
-
- public class File extends BaseObj {
- File(int id) {
- super(RenderScript.this);
- mID = id;
- }
- }
-
- public File fileOpen(String s) throws IllegalStateException, IllegalArgumentException
- {
- if(s.length() < 1) {
- throw new IllegalArgumentException("fileOpen does not accept a zero length string.");
- }
-
- try {
- byte[] bytes = s.getBytes("UTF-8");
- int id = nFileOpen(bytes);
- return new File(id);
- } catch (java.io.UnsupportedEncodingException e) {
- throw new RuntimeException(e);
- }
- }
-
-
///////////////////////////////////////////////////////////////////////////////////
// Root state
- private int safeID(BaseObj o) {
+ protected int safeID(BaseObj o) {
if(o != null) {
return o.mID;
}
return 0;
}
-
- public void contextBindRootScript(Script s) {
- nContextBindRootScript(safeID(s));
- }
-
- public void contextBindProgramFragmentStore(ProgramStore p) {
- nContextBindProgramFragmentStore(safeID(p));
- }
-
- public void contextBindProgramFragment(ProgramFragment p) {
- nContextBindProgramFragment(safeID(p));
- }
-
- public void contextBindProgramRaster(ProgramRaster p) {
- nContextBindProgramRaster(safeID(p));
- }
-
- public void contextBindProgramVertex(ProgramVertex p) {
- nContextBindProgramVertex(safeID(p));
- }
-
}
diff --git a/graphics/java/android/renderscript/RenderScriptGL.java b/graphics/java/android/renderscript/RenderScriptGL.java
new file mode 100644
index 0000000..d1df23d
--- /dev/null
+++ b/graphics/java/android/renderscript/RenderScriptGL.java
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.renderscript;
+
+import java.lang.reflect.Field;
+
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.util.Config;
+import android.util.Log;
+import android.view.Surface;
+
+
+/**
+ * @hide
+ *
+ **/
+public class RenderScriptGL extends RenderScript {
+ private Surface mSurface;
+ int mWidth;
+ int mHeight;
+
+
+ public RenderScriptGL(boolean useDepth, boolean forceSW) {
+ mSurface = null;
+ mWidth = 0;
+ mHeight = 0;
+ mDev = nDeviceCreate();
+ if(forceSW) {
+ nDeviceSetConfig(mDev, 0, 1);
+ }
+ mContext = nContextCreateGL(mDev, 0, useDepth);
+ mMessageThread = new MessageThread(this);
+ mMessageThread.start();
+ Element.initPredefined(this);
+ }
+
+ public void contextSetSurface(int w, int h, Surface sur) {
+ mSurface = sur;
+ mWidth = w;
+ mHeight = h;
+ validate();
+ nContextSetSurface(w, h, mSurface);
+ }
+
+
+ void pause() {
+ validate();
+ nContextPause();
+ }
+
+ void resume() {
+ validate();
+ nContextResume();
+ }
+
+
+ public void contextBindRootScript(Script s) {
+ validate();
+ nContextBindRootScript(safeID(s));
+ }
+
+ public void contextBindProgramFragmentStore(ProgramStore p) {
+ validate();
+ nContextBindProgramFragmentStore(safeID(p));
+ }
+
+ public void contextBindProgramFragment(ProgramFragment p) {
+ validate();
+ nContextBindProgramFragment(safeID(p));
+ }
+
+ public void contextBindProgramRaster(ProgramRaster p) {
+ validate();
+ nContextBindProgramRaster(safeID(p));
+ }
+
+ public void contextBindProgramVertex(ProgramVertex p) {
+ validate();
+ nContextBindProgramVertex(safeID(p));
+ }
+
+
+
+
+ //////////////////////////////////////////////////////////////////////////////////
+ // File
+
+ public class File extends BaseObj {
+ File(int id) {
+ super(RenderScriptGL.this);
+ mID = id;
+ }
+ }
+
+ public File fileOpen(String s) throws IllegalStateException, IllegalArgumentException
+ {
+ if(s.length() < 1) {
+ throw new IllegalArgumentException("fileOpen does not accept a zero length string.");
+ }
+
+ try {
+ byte[] bytes = s.getBytes("UTF-8");
+ int id = nFileOpen(bytes);
+ return new File(id);
+ } catch (java.io.UnsupportedEncodingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
+
+
diff --git a/graphics/java/android/renderscript/Sampler.java b/graphics/java/android/renderscript/Sampler.java
index 625a576..40ba722 100644
--- a/graphics/java/android/renderscript/Sampler.java
+++ b/graphics/java/android/renderscript/Sampler.java
@@ -69,23 +69,45 @@ public class Sampler extends BaseObj {
}
public void setMin(Value v) {
- mMin = v;
+ if (v == Value.NEAREST ||
+ v == Value.LINEAR ||
+ v == Value.LINEAR_MIP_LINEAR) {
+ mMin = v;
+ } else {
+ throw new IllegalArgumentException("Invalid value");
+ }
}
public void setMag(Value v) {
- mMag = v;
+ if (v == Value.NEAREST || v == Value.LINEAR) {
+ mMag = v;
+ } else {
+ throw new IllegalArgumentException("Invalid value");
+ }
}
public void setWrapS(Value v) {
- mWrapS = v;
+ if (v == Value.WRAP || v == Value.CLAMP) {
+ mWrapS = v;
+ } else {
+ throw new IllegalArgumentException("Invalid value");
+ }
}
public void setWrapT(Value v) {
- mWrapT = v;
+ if (v == Value.WRAP || v == Value.CLAMP) {
+ mWrapT = v;
+ } else {
+ throw new IllegalArgumentException("Invalid value");
+ }
}
public void setWrapR(Value v) {
- mWrapR = v;
+ if (v == Value.WRAP || v == Value.CLAMP) {
+ mWrapR = v;
+ } else {
+ throw new IllegalArgumentException("Invalid value");
+ }
}
static synchronized Sampler internalCreate(RenderScript rs, Builder b) {
diff --git a/graphics/java/android/renderscript/SimpleMesh.java b/graphics/java/android/renderscript/SimpleMesh.java
index f45074e..4a217a9 100644
--- a/graphics/java/android/renderscript/SimpleMesh.java
+++ b/graphics/java/android/renderscript/SimpleMesh.java
@@ -313,28 +313,36 @@ public class SimpleMesh extends BaseObj {
public SimpleMesh create() {
Element.Builder b = new Element.Builder(mRS);
int floatCount = mVtxSize;
- if (mVtxSize == 2) {
- b.addFloatXY();
- } else {
- b.addFloatXYZ();
- }
+ b.add(Element.createAttrib(mRS,
+ Element.DataType.FLOAT_32,
+ Element.DataKind.POSITION,
+ mVtxSize), "position");
if ((mFlags & COLOR) != 0) {
floatCount += 4;
- b.addFloatRGBA();
+ b.add(Element.createAttrib(mRS,
+ Element.DataType.FLOAT_32,
+ Element.DataKind.COLOR,
+ 4), "color");
}
if ((mFlags & TEXTURE_0) != 0) {
floatCount += 2;
- b.addFloatST();
+ b.add(Element.createAttrib(mRS,
+ Element.DataType.FLOAT_32,
+ Element.DataKind.TEXTURE,
+ 2), "texture");
}
if ((mFlags & NORMAL) != 0) {
floatCount += 3;
- b.addFloatNorm();
+ b.add(Element.createAttrib(mRS,
+ Element.DataType.FLOAT_32,
+ Element.DataKind.NORMAL,
+ 3), "normal");
}
mElement = b.create();
Builder smb = new Builder(mRS);
smb.addVertexType(mElement, mVtxCount / floatCount);
- smb.setIndexType(Element.INDEX_16(mRS), mIndexCount);
+ smb.setIndexType(Element.createIndex(mRS), mIndexCount);
smb.setPrimitive(Primitive.TRIANGLE);
SimpleMesh sm = smb.create();
diff --git a/graphics/java/android/renderscript/Type.java b/graphics/java/android/renderscript/Type.java
index ad4cf6b..62d3867 100644
--- a/graphics/java/android/renderscript/Type.java
+++ b/graphics/java/android/renderscript/Type.java
@@ -34,6 +34,9 @@ public class Type extends BaseObj {
private int mNativeCache;
Class mJavaClass;
+ public Element getElement() {
+ return mElement;
+ }
public int getX() {
return mDimX;
@@ -122,16 +125,16 @@ public class Type extends BaseObj {
Field f = fields[ct];
Class fc = f.getType();
if(fc == int.class) {
- arTypes[ct] = Element.DataType.SIGNED.mID;
+ arTypes[ct] = Element.DataType.SIGNED_32.mID;
arBits[ct] = 32;
} else if(fc == short.class) {
- arTypes[ct] = Element.DataType.SIGNED.mID;
+ arTypes[ct] = Element.DataType.SIGNED_16.mID;
arBits[ct] = 16;
} else if(fc == byte.class) {
- arTypes[ct] = Element.DataType.SIGNED.mID;
+ arTypes[ct] = Element.DataType.SIGNED_8.mID;
arBits[ct] = 8;
} else if(fc == float.class) {
- arTypes[ct] = Element.DataType.FLOAT.mID;
+ arTypes[ct] = Element.DataType.FLOAT_32.mID;
arBits[ct] = 32;
} else {
throw new IllegalArgumentException("Unkown field type");
diff --git a/graphics/java/android/renderscript/Vector2f.java b/graphics/java/android/renderscript/Vector2f.java
new file mode 100644
index 0000000..567d57f
--- /dev/null
+++ b/graphics/java/android/renderscript/Vector2f.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.renderscript;
+
+import java.lang.Math;
+import android.util.Log;
+
+
+/**
+ * @hide
+ *
+ **/
+public class Vector2f {
+ public Vector2f() {
+ }
+
+ public float x;
+ public float y;
+}
+
+
+
+
diff --git a/graphics/java/android/renderscript/Vector3f.java b/graphics/java/android/renderscript/Vector3f.java
new file mode 100644
index 0000000..f2842f3
--- /dev/null
+++ b/graphics/java/android/renderscript/Vector3f.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.renderscript;
+
+import java.lang.Math;
+import android.util.Log;
+
+
+/**
+ * @hide
+ *
+ **/
+public class Vector3f {
+ public Vector3f() {
+ }
+
+ public float x;
+ public float y;
+ public float z;
+}
+
+
+
+
diff --git a/graphics/java/android/renderscript/Vector4f.java b/graphics/java/android/renderscript/Vector4f.java
new file mode 100644
index 0000000..fabd959
--- /dev/null
+++ b/graphics/java/android/renderscript/Vector4f.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.renderscript;
+
+import java.lang.Math;
+import android.util.Log;
+
+
+/**
+ * @hide
+ *
+ **/
+public class Vector4f {
+ public Vector4f() {
+ }
+
+ public float x;
+ public float y;
+ public float z;
+ public float w;
+}
+
+
+
diff --git a/graphics/jni/Android.mk b/graphics/jni/Android.mk
index 799fcbb..8476be1 100644
--- a/graphics/jni/Android.mk
+++ b/graphics/jni/Android.mk
@@ -19,7 +19,8 @@ LOCAL_SHARED_LIBRARIES := \
libcutils \
libskia \
libutils \
- libui
+ libui \
+ libsurfaceflinger_client
LOCAL_STATIC_LIBRARIES :=
diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp
index af3bc74..d8e0393 100644
--- a/graphics/jni/android_renderscript_RenderScript.cpp
+++ b/graphics/jni/android_renderscript_RenderScript.cpp
@@ -23,7 +23,7 @@
#include <math.h>
#include <utils/misc.h>
-#include <ui/Surface.h>
+#include <surfaceflinger/Surface.h>
#include <core/SkBitmap.h>
#include <core/SkPixelRef.h>
@@ -151,10 +151,17 @@ nDeviceSetConfig(JNIEnv *_env, jobject _this, jint dev, jint p, jint value)
}
static jint
-nContextCreate(JNIEnv *_env, jobject _this, jint dev, jint ver, jboolean useDepth)
+nContextCreate(JNIEnv *_env, jobject _this, jint dev, jint ver)
{
LOG_API("nContextCreate");
- return (jint)rsContextCreate((RsDevice)dev, ver, useDepth);
+ return (jint)rsContextCreate((RsDevice)dev, ver);
+}
+
+static jint
+nContextCreateGL(JNIEnv *_env, jobject _this, jint dev, jint ver, jboolean useDepth)
+{
+ LOG_API("nContextCreateGL");
+ return (jint)rsContextCreateGL((RsDevice)dev, ver, useDepth);
}
static void
@@ -247,36 +254,39 @@ static void nContextDeinitToClient(JNIEnv *_env, jobject _this)
}
-static void
-nElementBegin(JNIEnv *_env, jobject _this)
+static jint
+nElementCreate(JNIEnv *_env, jobject _this, jint type, jint kind, jboolean norm, jint size)
{
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nElementBegin, con(%p)", con);
- rsElementBegin(con);
+ LOG_API("nElementCreate, con(%p), type(%i), kind(%i), norm(%i), size(%i)", con, type, kind, norm, size);
+ return (jint)rsElementCreate(con, (RsDataType)type, (RsDataKind)kind, norm, size);
}
-
-static void
-nElementAdd(JNIEnv *_env, jobject _this, jint kind, jint type, jboolean norm, jint bits, jstring name)
+static jint
+nElementCreate2(JNIEnv *_env, jobject _this, jintArray _ids, jobjectArray _names)
{
+ int fieldCount = _env->GetArrayLength(_ids);
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- const char* n = NULL;
- if (name) {
- n = _env->GetStringUTFChars(name, NULL);
+ LOG_API("nElementCreate2, con(%p)", con);
+
+ jint *ids = _env->GetIntArrayElements(_ids, NULL);
+ const char ** nameArray = (const char **)calloc(fieldCount, sizeof(char *));
+ size_t* sizeArray = (size_t*)calloc(fieldCount, sizeof(size_t));
+
+ for (int ct=0; ct < fieldCount; ct++) {
+ jstring s = (jstring)_env->GetObjectArrayElement(_names, ct);
+ nameArray[ct] = _env->GetStringUTFChars(s, NULL);
+ sizeArray[ct] = _env->GetStringUTFLength(s);
}
- LOG_API("nElementAdd, con(%p), kind(%i), type(%i), norm(%i), bits(%i)", con, kind, type, norm, bits);
- rsElementAdd(con, (RsDataKind)kind, (RsDataType)type, norm != 0, (size_t)bits, n);
- if (n) {
- _env->ReleaseStringUTFChars(name, n);
+ jint id = (jint)rsElementCreate2(con, fieldCount, (RsElement *)ids, nameArray, sizeArray);
+ for (int ct=0; ct < fieldCount; ct++) {
+ jstring s = (jstring)_env->GetObjectArrayElement(_names, ct);
+ _env->ReleaseStringUTFChars(s, nameArray[ct]);
}
-}
-
-static jint
-nElementCreate(JNIEnv *_env, jobject _this)
-{
- RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nElementCreate, con(%p)", con);
- return (jint)rsElementCreate(con);
+ _env->ReleaseIntArrayElements(_ids, ids, JNI_ABORT);
+ free(nameArray);
+ free(sizeArray);
+ return (jint)id;
}
// -----------------------------------
@@ -395,26 +405,24 @@ nTypeSetupFields(JNIEnv *_env, jobject _this, jobject _type, jintArray _types, j
tfc[ct].bits = fBits[ct];
switch(fType[ct]) {
- case RS_TYPE_FLOAT:
+ case RS_TYPE_FLOAT_32:
tfc[ct].ptr = SF_LoadFloat;
tfc[ct].readPtr = SF_SaveFloat;
break;
- case RS_TYPE_UNSIGNED:
- case RS_TYPE_SIGNED:
- switch(tfc[ct].bits) {
- case 32:
- tfc[ct].ptr = SF_LoadInt;
- tfc[ct].readPtr = SF_SaveInt;
- break;
- case 16:
- tfc[ct].ptr = SF_LoadShort;
- tfc[ct].readPtr = SF_SaveShort;
- break;
- case 8:
- tfc[ct].ptr = SF_LoadByte;
- tfc[ct].readPtr = SF_SaveByte;
- 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;
@@ -436,11 +444,11 @@ nAllocationCreateTyped(JNIEnv *_env, jobject _this, jint e)
}
static void
-nAllocationUploadToTexture(JNIEnv *_env, jobject _this, jint a, jint mip)
+nAllocationUploadToTexture(JNIEnv *_env, jobject _this, jint a, jboolean genMip, jint mip)
{
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nAllocationUploadToTexture, con(%p), a(%p), mip(%i)", con, (RsAllocation)a, mip);
- rsAllocationUploadToTexture(con, (RsAllocation)a, mip);
+ LOG_API("nAllocationUploadToTexture, con(%p), a(%p), genMip(%i), mip(%i)", con, (RsAllocation)a, genMip, mip);
+ rsAllocationUploadToTexture(con, (RsAllocation)a, genMip, mip);
}
static void
@@ -493,6 +501,26 @@ nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jint dstFmt, jboolean g
return 0;
}
+static void ReleaseBitmapCallback(void *bmp)
+{
+ SkBitmap const * nativeBitmap = (SkBitmap const *)bmp;
+ nativeBitmap->unlockPixels();
+}
+
+static int
+nAllocationCreateBitmapRef(JNIEnv *_env, jobject _this, jint type, jobject jbitmap)
+{
+ RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
+ SkBitmap * nativeBitmap =
+ (SkBitmap *)_env->GetIntField(jbitmap, gNativeBitmapID);
+
+
+ nativeBitmap->lockPixels();
+ void* ptr = nativeBitmap->getPixels();
+ jint id = (jint)rsAllocationCreateBitmapRef(con, (RsType)type, ptr, nativeBitmap, ReleaseBitmapCallback);
+ return id;
+}
+
static int
nAllocationCreateFromAssetStream(JNIEnv *_env, jobject _this, jint dstFmt, jboolean genMips, jint native_asset)
{
@@ -1056,87 +1084,89 @@ nProgramFragmentStoreCreate(JNIEnv *_env, jobject _this)
// ---------------------------------------------------------------------------
static void
-nProgramFragmentBegin(JNIEnv *_env, jobject _this, jint in, jint out, jboolean pointSpriteEnable)
+nProgramBindConstants(JNIEnv *_env, jobject _this, jint vpv, jint slot, jint a)
{
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nProgramFragmentBegin, con(%p), in(%p), out(%p) PointSprite(%i)", con, (RsElement)in, (RsElement)out, pointSpriteEnable);
- rsProgramFragmentBegin(con, (RsElement)in, (RsElement)out, pointSpriteEnable);
+ LOG_API("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", con, (RsProgramVertex)vpv, slot, (RsAllocation)a);
+ rsProgramBindConstants(con, (RsProgram)vpv, slot, (RsAllocation)a);
}
static void
-nProgramFragmentBindTexture(JNIEnv *_env, jobject _this, jint vpf, jint slot, jint a)
+nProgramBindTexture(JNIEnv *_env, jobject _this, jint vpf, jint slot, jint a)
{
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nProgramFragmentBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
- rsProgramFragmentBindTexture(con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
+ LOG_API("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
+ rsProgramBindTexture(con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
}
static void
-nProgramFragmentBindSampler(JNIEnv *_env, jobject _this, jint vpf, jint slot, jint a)
+nProgramBindSampler(JNIEnv *_env, jobject _this, jint vpf, jint slot, jint a)
{
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nProgramFragmentBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsSampler)a);
- rsProgramFragmentBindSampler(con, (RsProgramFragment)vpf, slot, (RsSampler)a);
+ LOG_API("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsSampler)a);
+ rsProgramBindSampler(con, (RsProgramFragment)vpf, slot, (RsSampler)a);
}
-static void
-nProgramFragmentSetSlot(JNIEnv *_env, jobject _this, jint slot, jboolean enable, jint env, jint vt)
-{
- RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nProgramFragmentSetType, con(%p), slot(%i), enable(%i), env(%i), vt(%p)", con, slot, enable, env, (RsType)vt);
- rsProgramFragmentSetSlot(con, slot, enable, (RsTexEnvMode)env, (RsType)vt);
-}
+// ---------------------------------------------------------------------------
static jint
-nProgramFragmentCreate(JNIEnv *_env, jobject _this, jint slot, jboolean enable)
+nProgramFragmentCreate(JNIEnv *_env, jobject _this, jintArray params)
{
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nProgramFragmentCreate, con(%p)", con);
- return (jint)rsProgramFragmentCreate(con);
-}
+ jint *paramPtr = _env->GetIntArrayElements(params, NULL);
+ jint paramLen = _env->GetArrayLength(params);
-// ---------------------------------------------------------------------------
+ LOG_API("nProgramFragmentCreate, con(%p), paramLen(%i)", con, paramLen);
-static void
-nProgramVertexBegin(JNIEnv *_env, jobject _this, jint in, jint out)
-{
- RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nProgramVertexBegin, con(%p), in(%p), out(%p)", con, (RsElement)in, (RsElement)out);
- rsProgramVertexBegin(con, (RsElement)in, (RsElement)out);
+ jint ret = (jint)rsProgramFragmentCreate(con, (uint32_t *)paramPtr, paramLen);
+ _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT);
+ return ret;
}
-static void
-nProgramVertexBindAllocation(JNIEnv *_env, jobject _this, jint vpv, jint a)
+static jint
+nProgramFragmentCreate2(JNIEnv *_env, jobject _this, jstring shader, jintArray params)
{
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nProgramVertexBindAllocation, con(%p), vpf(%p), a(%p)", con, (RsProgramVertex)vpv, (RsAllocation)a);
- rsProgramVertexBindAllocation(con, (RsProgramFragment)vpv, (RsAllocation)a);
-}
+ const char* shaderUTF = _env->GetStringUTFChars(shader, NULL);
+ jint shaderLen = _env->GetStringUTFLength(shader);
+ jint *paramPtr = _env->GetIntArrayElements(params, NULL);
+ jint paramLen = _env->GetArrayLength(params);
-static void
-nProgramVertexSetTextureMatrixEnable(JNIEnv *_env, jobject _this, jboolean enable)
-{
- RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nProgramVertexSetTextureMatrixEnable, con(%p), enable(%i)", con, enable);
- rsProgramVertexSetTextureMatrixEnable(con, enable);
+ LOG_API("nProgramFragmentCreate2, con(%p), shaderLen(%i), paramLen(%i)", con, shaderLen, paramLen);
+
+ jint ret = (jint)rsProgramFragmentCreate2(con, shaderUTF, shaderLen, (uint32_t *)paramPtr, paramLen);
+ _env->ReleaseStringUTFChars(shader, shaderUTF);
+ _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT);
+ return ret;
}
-static void
-nProgramVertexAddLight(JNIEnv *_env, jobject _this, jint light)
+
+// ---------------------------------------------------------------------------
+
+static jint
+nProgramVertexCreate(JNIEnv *_env, jobject _this, jboolean texMat)
{
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nProgramVertexAddLight, con(%p), light(%p)", con, (RsLight)light);
- rsProgramVertexAddLight(con, (RsLight)light);
+ LOG_API("nProgramVertexCreate, con(%p), texMat(%i)", con, texMat);
+ return (jint)rsProgramVertexCreate(con, texMat);
}
static jint
-nProgramVertexCreate(JNIEnv *_env, jobject _this)
+nProgramVertexCreate2(JNIEnv *_env, jobject _this, jstring shader, jintArray params)
{
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nProgramVertexCreate, con(%p)", con);
- return (jint)rsProgramVertexCreate(con);
-}
+ const char* shaderUTF = _env->GetStringUTFChars(shader, NULL);
+ jint shaderLen = _env->GetStringUTFLength(shader);
+ jint *paramPtr = _env->GetIntArrayElements(params, NULL);
+ jint paramLen = _env->GetArrayLength(params);
+ LOG_API("nProgramVertexCreate2, con(%p), shaderLen(%i), paramLen(%i)", con, shaderLen, paramLen);
+
+ jint ret = (jint)rsProgramVertexCreate2(con, shaderUTF, shaderLen, (uint32_t *)paramPtr, paramLen);
+ _env->ReleaseStringUTFChars(shader, shaderUTF);
+ _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT);
+ return ret;
+}
// ---------------------------------------------------------------------------
@@ -1209,26 +1239,6 @@ nContextBindProgramRaster(JNIEnv *_env, jobject _this, jint pf)
rsContextBindProgramRaster(con, (RsProgramRaster)pf);
}
-static void
-nContextAddDefineI32(JNIEnv *_env, jobject _this, jstring name, jint value)
-{
- RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- const char* n = _env->GetStringUTFChars(name, NULL);
- LOG_API("nScriptCAddDefineI32, con(%p) name(%s) value(%d)", con, n, value);
- rsContextSetDefineI32(con, n, value);
- _env->ReleaseStringUTFChars(name, n);
-}
-
-static void
-nContextAddDefineF(JNIEnv *_env, jobject _this, jstring name, jfloat value)
-{
- RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- const char* n = _env->GetStringUTFChars(name, NULL);
- LOG_API("nScriptCAddDefineF, con(%p) name(%s) value(%f)", con, n, value);
- rsContextSetDefineF(con, n, value);
- _env->ReleaseStringUTFChars(name, n);
-}
-
// ---------------------------------------------------------------------------
@@ -1349,7 +1359,8 @@ static JNINativeMethod methods[] = {
{"nDeviceCreate", "()I", (void*)nDeviceCreate },
{"nDeviceDestroy", "(I)V", (void*)nDeviceDestroy },
{"nDeviceSetConfig", "(III)V", (void*)nDeviceSetConfig },
-{"nContextCreate", "(IIZ)I", (void*)nContextCreate },
+{"nContextCreate", "(II)I", (void*)nContextCreate },
+{"nContextCreateGL", "(IIZ)I", (void*)nContextCreateGL },
{"nContextSetPriority", "(I)V", (void*)nContextSetPriority },
{"nContextSetSurface", "(IILandroid/view/Surface;)V", (void*)nContextSetSurface },
{"nContextDestroy", "(I)V", (void*)nContextDestroy },
@@ -1365,9 +1376,8 @@ static JNINativeMethod methods[] = {
{"nFileOpen", "([B)I", (void*)nFileOpen },
-{"nElementBegin", "()V", (void*)nElementBegin },
-{"nElementAdd", "(IIZILjava/lang/String;)V", (void*)nElementAdd },
-{"nElementCreate", "()I", (void*)nElementCreate },
+{"nElementCreate", "(IIZI)I", (void*)nElementCreate },
+{"nElementCreate2", "([I[Ljava/lang/String;)I", (void*)nElementCreate2 },
{"nTypeBegin", "(I)V", (void*)nTypeBegin },
{"nTypeAdd", "(II)V", (void*)nTypeAdd },
@@ -1377,9 +1387,10 @@ static JNINativeMethod methods[] = {
{"nAllocationCreateTyped", "(I)I", (void*)nAllocationCreateTyped },
{"nAllocationCreateFromBitmap", "(IZLandroid/graphics/Bitmap;)I", (void*)nAllocationCreateFromBitmap },
+{"nAllocationCreateBitmapRef", "(ILandroid/graphics/Bitmap;)I", (void*)nAllocationCreateBitmapRef },
{"nAllocationCreateFromBitmapBoxed","(IZLandroid/graphics/Bitmap;)I", (void*)nAllocationCreateFromBitmapBoxed },
{"nAllocationCreateFromAssetStream","(IZI)I", (void*)nAllocationCreateFromAssetStream },
-{"nAllocationUploadToTexture", "(II)V", (void*)nAllocationUploadToTexture },
+{"nAllocationUploadToTexture", "(IZI)V", (void*)nAllocationUploadToTexture },
{"nAllocationUploadToBufferObject","(I)V", (void*)nAllocationUploadToBufferObject },
{"nAllocationSubData1D", "(III[II)V", (void*)nAllocationSubData1D_i },
{"nAllocationSubData1D", "(III[SI)V", (void*)nAllocationSubData1D_s },
@@ -1432,21 +1443,19 @@ static JNINativeMethod methods[] = {
{"nProgramFragmentStoreDither", "(Z)V", (void*)nProgramFragmentStoreDither },
{"nProgramFragmentStoreCreate", "()I", (void*)nProgramFragmentStoreCreate },
-{"nProgramFragmentBegin", "(IIZ)V", (void*)nProgramFragmentBegin },
-{"nProgramFragmentBindTexture", "(III)V", (void*)nProgramFragmentBindTexture },
-{"nProgramFragmentBindSampler", "(III)V", (void*)nProgramFragmentBindSampler },
-{"nProgramFragmentSetSlot", "(IZII)V", (void*)nProgramFragmentSetSlot },
-{"nProgramFragmentCreate", "()I", (void*)nProgramFragmentCreate },
+{"nProgramBindConstants", "(III)V", (void*)nProgramBindConstants },
+{"nProgramBindTexture", "(III)V", (void*)nProgramBindTexture },
+{"nProgramBindSampler", "(III)V", (void*)nProgramBindSampler },
+
+{"nProgramFragmentCreate", "([I)I", (void*)nProgramFragmentCreate },
+{"nProgramFragmentCreate2", "(Ljava/lang/String;[I)I", (void*)nProgramFragmentCreate2 },
{"nProgramRasterCreate", "(IIZZZ)I", (void*)nProgramRasterCreate },
{"nProgramRasterSetPointSize", "(IF)V", (void*)nProgramRasterSetPointSize },
{"nProgramRasterSetLineWidth", "(IF)V", (void*)nProgramRasterSetLineWidth },
-{"nProgramVertexBindAllocation", "(II)V", (void*)nProgramVertexBindAllocation },
-{"nProgramVertexBegin", "(II)V", (void*)nProgramVertexBegin },
-{"nProgramVertexSetTextureMatrixEnable", "(Z)V", (void*)nProgramVertexSetTextureMatrixEnable },
-{"nProgramVertexAddLight", "(I)V", (void*)nProgramVertexAddLight },
-{"nProgramVertexCreate", "()I", (void*)nProgramVertexCreate },
+{"nProgramVertexCreate", "(Z)I", (void*)nProgramVertexCreate },
+{"nProgramVertexCreate2", "(Ljava/lang/String;[I)I", (void*)nProgramVertexCreate2 },
{"nLightBegin", "()V", (void*)nLightBegin },
{"nLightSetIsMono", "(Z)V", (void*)nLightSetIsMono },
diff --git a/graphics/tests/graphicstests/Android.mk b/graphics/tests/graphicstests/Android.mk
new file mode 100644
index 0000000..1845395
--- /dev/null
+++ b/graphics/tests/graphicstests/Android.mk
@@ -0,0 +1,14 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+# We only want this apk build for tests.
+LOCAL_MODULE_TAGS := tests
+
+# Include all test java files.
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_JAVA_LIBRARIES := android.test.runner
+LOCAL_PACKAGE_NAME := FrameworksGraphicsTests
+
+include $(BUILD_PACKAGE)
+
diff --git a/graphics/tests/graphicstests/AndroidManifest.xml b/graphics/tests/graphicstests/AndroidManifest.xml
new file mode 100644
index 0000000..5fb5959
--- /dev/null
+++ b/graphics/tests/graphicstests/AndroidManifest.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2008 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.frameworks.graphicstests">
+ <uses-permission android:name="android.permission.RECEIVE_SMS"/>
+ <uses-permission android:name="android.permission.INTERNET" />
+ <uses-permission android:name="android.permission.READ_CONTACTS" />
+ <uses-permission android:name="android.permission.WRITE_CONTACTS" />
+ <uses-permission android:name="android.permission.WAKE_LOCK" />
+ <uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />
+ <uses-permission android:name="android.permission.WRITE_APN_SETTINGS" />
+ <uses-permission android:name="android.permission.BROADCAST_STICKY" />
+
+
+ <application>
+ <uses-library android:name="android.test.runner" />
+ </application>
+
+ <instrumentation
+ android:name="android.test.InstrumentationTestRunner"
+ android:targetPackage="com.android.frameworks.graphicstests"
+ android:label="Frameworks Graphics Tests" />
+</manifest>
diff --git a/graphics/tests/graphicstests/res/drawable/test128x96.png b/graphics/tests/graphicstests/res/drawable/test128x96.png
new file mode 100644
index 0000000..28dc925
--- /dev/null
+++ b/graphics/tests/graphicstests/res/drawable/test128x96.png
Binary files differ
diff --git a/graphics/tests/graphicstests/res/drawable/test16x12.png b/graphics/tests/graphicstests/res/drawable/test16x12.png
new file mode 100644
index 0000000..1a3c7e5
--- /dev/null
+++ b/graphics/tests/graphicstests/res/drawable/test16x12.png
Binary files differ
diff --git a/graphics/tests/graphicstests/res/drawable/test256x192.png b/graphics/tests/graphicstests/res/drawable/test256x192.png
new file mode 100644
index 0000000..ce8ee04
--- /dev/null
+++ b/graphics/tests/graphicstests/res/drawable/test256x192.png
Binary files differ
diff --git a/graphics/tests/graphicstests/res/drawable/test320x240.png b/graphics/tests/graphicstests/res/drawable/test320x240.png
new file mode 100644
index 0000000..9b5800d
--- /dev/null
+++ b/graphics/tests/graphicstests/res/drawable/test320x240.png
Binary files differ
diff --git a/graphics/tests/graphicstests/res/drawable/test32x24.png b/graphics/tests/graphicstests/res/drawable/test32x24.png
new file mode 100644
index 0000000..76bab75
--- /dev/null
+++ b/graphics/tests/graphicstests/res/drawable/test32x24.png
Binary files differ
diff --git a/graphics/tests/graphicstests/res/drawable/test64x48.png b/graphics/tests/graphicstests/res/drawable/test64x48.png
new file mode 100644
index 0000000..9119613
--- /dev/null
+++ b/graphics/tests/graphicstests/res/drawable/test64x48.png
Binary files differ
diff --git a/graphics/tests/graphicstests/src/android/graphics/BitmapTest.java b/graphics/tests/graphicstests/src/android/graphics/BitmapTest.java
new file mode 100644
index 0000000..6734bb7
--- /dev/null
+++ b/graphics/tests/graphicstests/src/android/graphics/BitmapTest.java
@@ -0,0 +1,232 @@
+/*
+ * Copyright (C) 2006 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.graphics.Bitmap;
+import android.graphics.Color;
+import android.test.suitebuilder.annotation.SmallTest;
+import junit.framework.TestCase;
+
+
+public class BitmapTest extends TestCase {
+
+ @SmallTest
+ public void testBasic() throws Exception {
+ Bitmap bm1 = Bitmap.createBitmap(100, 200, Bitmap.Config.ARGB_8888);
+ Bitmap bm2 = Bitmap.createBitmap(100, 200, Bitmap.Config.RGB_565);
+ Bitmap bm3 = Bitmap.createBitmap(100, 200, Bitmap.Config.ARGB_4444);
+
+ assertTrue("mutability", bm1.isMutable());
+ assertTrue("mutability", bm2.isMutable());
+ assertTrue("mutability", bm3.isMutable());
+
+ assertEquals("width", 100, bm1.getWidth());
+ assertEquals("width", 100, bm2.getWidth());
+ assertEquals("width", 100, bm3.getWidth());
+
+ assertEquals("rowbytes", 400, bm1.getRowBytes());
+ assertEquals("rowbytes", 200, bm2.getRowBytes());
+ assertEquals("rowbytes", 200, bm3.getRowBytes());
+
+ assertEquals("height", 200, bm1.getHeight());
+ assertEquals("height", 200, bm2.getHeight());
+ assertEquals("height", 200, bm3.getHeight());
+
+ assertTrue("hasAlpha", bm1.hasAlpha());
+ assertFalse("hasAlpha", bm2.hasAlpha());
+ assertTrue("hasAlpha", bm3.hasAlpha());
+
+ assertTrue("getConfig", bm1.getConfig() == Bitmap.Config.ARGB_8888);
+ assertTrue("getConfig", bm2.getConfig() == Bitmap.Config.RGB_565);
+ assertTrue("getConfig", bm3.getConfig() == Bitmap.Config.ARGB_4444);
+ }
+
+ @SmallTest
+ public void testMutability() throws Exception {
+ Bitmap bm1 = Bitmap.createBitmap(100, 200, Bitmap.Config.ARGB_8888);
+ Bitmap bm2 = Bitmap.createBitmap(new int[100 * 200], 100, 200,
+ Bitmap.Config.ARGB_8888);
+
+ assertTrue("mutability", bm1.isMutable());
+ assertFalse("mutability", bm2.isMutable());
+
+ bm1.eraseColor(0);
+
+ try {
+ bm2.eraseColor(0);
+ fail("eraseColor should throw exception");
+ } catch (IllegalStateException ex) {
+ // safe to catch and ignore this
+ }
+ }
+
+ @SmallTest
+ public void testGetPixelsWithAlpha() throws Exception {
+ int[] colors = new int[100];
+ for (int i = 0; i < 100; i++) {
+ colors[i] = (0xFF << 24) | (i << 16) | (i << 8) | i;
+ }
+
+ Bitmap bm = Bitmap.createBitmap(colors, 10, 10,
+ Bitmap.Config.ARGB_8888);
+
+ int[] pixels = new int[100];
+ bm.getPixels(pixels, 0, 10, 0, 0, 10, 10);
+ for (int i = 0; i < 100; i++) {
+ int p = bm.getPixel(i % 10, i / 10);
+ assertEquals("getPixels", p, pixels[i]);
+ }
+
+ for (int i = 0; i < 100; i++) {
+ int p = bm.getPixel(i % 10, i / 10);
+ assertEquals("getPixel", p, colors[i]);
+ assertEquals("pixel value", p,
+ ((0xFF << 24) | (i << 16) | (i << 8) | i));
+ }
+
+ }
+
+ @SmallTest
+ public void testGetPixelsWithoutAlpha() throws Exception {
+ int[] colors = new int[100];
+ for (int i = 0; i < 100; i++) {
+ colors[i] = (0xFF << 24) | (i << 16) | (i << 8) | i;
+ }
+
+ Bitmap bm = Bitmap.createBitmap(colors, 10, 10, Bitmap.Config.RGB_565);
+
+ int[] pixels = new int[100];
+ bm.getPixels(pixels, 0, 10, 0, 0, 10, 10);
+ for (int i = 0; i < 100; i++) {
+ int p = bm.getPixel(i % 10, i / 10);
+ assertEquals("getPixels", p, pixels[i]);
+ }
+ }
+
+ @SmallTest
+ public void testSetPixelsWithAlpha() throws Exception {
+ int[] colors = new int[100];
+ for (int i = 0; i < 100; i++) {
+ colors[i] = (0xFF << 24) | (i << 16) | (i << 8) | i;
+ }
+
+ Bitmap.Config config = Bitmap.Config.ARGB_8888;
+ Bitmap bm1 = Bitmap.createBitmap(colors, 10, 10, config);
+ Bitmap bm2 = Bitmap.createBitmap(10, 10, config);
+
+ for (int i = 0; i < 100; i++) {
+ bm2.setPixel(i % 10, i / 10, colors[i]);
+ }
+
+ for (int i = 0; i < 100; i++) {
+ assertEquals("setPixel",
+ bm1.getPixel(i % 10, i / 10), bm2.getPixel(i % 10, i / 10));
+ }
+
+ for (int i = 0; i < 100; i++) {
+ assertEquals("setPixel value",
+ bm1.getPixel(i % 10, i / 10), colors[i]);
+ }
+ }
+
+ @SmallTest
+ public void testSetPixelsWithoutAlpha() throws Exception {
+ int[] colors = new int[100];
+ for (int i = 0; i < 100; i++) {
+ colors[i] = (0xFF << 24) | (i << 16) | (i << 8) | i;
+ }
+
+ Bitmap.Config config = Bitmap.Config.RGB_565;
+ Bitmap bm1 = Bitmap.createBitmap(colors, 10, 10, config);
+ Bitmap bm2 = Bitmap.createBitmap(10, 10, config);
+
+ for (int i = 0; i < 100; i++) {
+ bm2.setPixel(i % 10, i / 10, colors[i]);
+ }
+
+ for (int i = 0; i < 100; i++) {
+ assertEquals("setPixel", bm1.getPixel(i % 10, i / 10),
+ bm2.getPixel(i % 10, i / 10));
+ }
+ }
+
+ private static int computePrePostMul(int alpha, int comp) {
+ if (alpha == 0) {
+ return 0;
+ }
+ int premul = Math.round(alpha * comp / 255.f);
+ int unpre = Math.round(255.0f * premul / alpha);
+ return unpre;
+ }
+
+ @SmallTest
+ public void testSetPixelsWithNonOpaqueAlpha() throws Exception {
+ int[] colors = new int[256];
+ for (int i = 0; i < 256; i++) {
+ colors[i] = (i << 24) | (0xFF << 16) | (0x80 << 8) | 0;
+ }
+
+ Bitmap.Config config = Bitmap.Config.ARGB_8888;
+
+ // create a bitmap with the color array specified
+ Bitmap bm1 = Bitmap.createBitmap(colors, 16, 16, config);
+
+ // create a bitmap with no colors, but then call setPixels
+ Bitmap bm2 = Bitmap.createBitmap(16, 16, config);
+ bm2.setPixels(colors, 0, 16, 0, 0, 16, 16);
+
+ // now check that we did a good job returning the unpremultiplied alpha
+ final int tolerance = 1;
+ for (int i = 0; i < 256; i++) {
+ int c0 = colors[i];
+ int c1 = bm1.getPixel(i % 16, i / 16);
+ int c2 = bm2.getPixel(i % 16, i / 16);
+
+ // these two should always be identical
+ assertEquals("getPixel", c1, c2);
+
+ // comparing the original (c0) with the returned color is tricky,
+ // since it gets premultiplied during the set(), and unpremultiplied
+ // by the get().
+ int a0 = Color.alpha(c0);
+ int a1 = Color.alpha(c1);
+ assertEquals("alpha", a0, a1);
+
+ int r0 = Color.red(c0);
+ int r1 = Color.red(c1);
+ int rr = computePrePostMul(a0, r0);
+ assertTrue("red", Math.abs(rr - r1) <= tolerance);
+
+ int g0 = Color.green(c0);
+ int g1 = Color.green(c1);
+ int gg = computePrePostMul(a0, g0);
+ assertTrue("green", Math.abs(gg - g1) <= tolerance);
+
+ int b0 = Color.blue(c0);
+ int b1 = Color.blue(c1);
+ int bb = computePrePostMul(a0, b0);
+ assertTrue("blue", Math.abs(bb - b1) <= tolerance);
+
+ if (false) {
+ int cc = Color.argb(a0, rr, gg, bb);
+ android.util.Log.d("skia", "original " + Integer.toHexString(c0) +
+ " set+get " + Integer.toHexString(c1) +
+ " local " + Integer.toHexString(cc));
+ }
+ }
+ }
+}
diff --git a/graphics/tests/graphicstests/src/android/graphics/GraphicsPerformanceTests.java b/graphics/tests/graphicstests/src/android/graphics/GraphicsPerformanceTests.java
new file mode 100644
index 0000000..f60ac7b
--- /dev/null
+++ b/graphics/tests/graphicstests/src/android/graphics/GraphicsPerformanceTests.java
@@ -0,0 +1,450 @@
+/*
+ * Copyright (C) 2007 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 junit.framework.Assert;
+import android.content.Context;
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.test.AndroidTestCase;
+import android.test.PerformanceTestCase;
+import android.test.suitebuilder.annotation.Suppress;
+import android.util.Log;
+
+import com.android.frameworks.graphicstests.R;
+
+/**
+ * Graphics Performance Tests
+ *
+ */
+//We don't want to run these perf tests in the continuous build.
+@Suppress
+public class GraphicsPerformanceTests {
+ private static final String TAG = "GfxPerf";
+ public static String[] children() {
+ return new String[] {
+ // test decoding bitmaps of various sizes
+ DecodeBitmapTest.class.getName(),
+
+ // odd-sized bitmap drawing tests
+ DrawBitmap7x7.class.getName(),
+ DrawBitmap15x15.class.getName(),
+ DrawBitmap31x31.class.getName(),
+ DrawBitmap63x63.class.getName(),
+ DrawBitmap127x127.class.getName(),
+ DrawBitmap319x239.class.getName(),
+ DrawBitmap319x479.class.getName(),
+
+ // even-sized bitmap drawing tests
+ DrawBitmap8x8.class.getName(),
+ DrawBitmap16x16.class.getName(),
+ DrawBitmap32x32.class.getName(),
+ DrawBitmap64x64.class.getName(),
+ DrawBitmap128x128.class.getName(),
+ DrawBitmap320x240.class.getName(),
+ DrawBitmap320x480.class.getName()};
+ }
+
+ /**
+ * Base class for all graphics tests
+ *
+ */
+ public static abstract class GraphicsTestBase extends AndroidTestCase
+ implements PerformanceTestCase {
+ /** Target "screen" (bitmap) width and height */
+ private static final int DEFAULT_ITERATIONS = 1;
+ private static final int SCREEN_WIDTH = 320;
+ private static final int SCREEN_HEIGHT = 480;
+
+ /** Number of iterations to pass back to harness. Subclass should override */
+ protected int mIterations = 1;
+
+ /** Bitmap we allocate and draw to */
+ protected Bitmap mDestBitmap;
+
+ /** Canvas of drawing routines */
+ protected Canvas mCanvas;
+
+ /** Style and color information (uses defaults) */
+ protected Paint mPaint;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ // Create drawable bitmap for rendering into
+ mDestBitmap = Bitmap.createBitmap(SCREEN_WIDTH, SCREEN_HEIGHT,
+ Bitmap.Config.RGB_565);
+ // Set of drawing routines
+ mCanvas = new Canvas(mDestBitmap);
+ // Styles
+ mPaint = new Paint();
+ // Ask subclass for number of iterations
+ mIterations = getIterations();
+ }
+
+ // A reasonable default
+ public int getIterations() {
+ return DEFAULT_ITERATIONS;
+ }
+
+ public boolean isPerformanceOnly() {
+ return true;
+ }
+
+ public int startPerformance(Intermediates intermediates) {
+ intermediates.setInternalIterations(mIterations * 10);
+ return 0;
+ }
+ }
+
+ /**
+ * Tests time to decode a number of sizes of images.
+ */
+ public static class DecodeBitmapTest extends GraphicsTestBase {
+ /** Number of times to run this test */
+ private static final int DECODE_ITERATIONS = 10;
+
+ /** Used to access package bitmap images */
+ private Resources mResources;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+
+ // For bitmap resources
+ Context context = getContext();
+ Assert.assertNotNull(context);
+ mResources = context.getResources();
+ Assert.assertNotNull(mResources);
+ }
+
+ @Override
+ public int getIterations() {
+ return DECODE_ITERATIONS;
+ }
+
+ public void testDecodeBitmap() {
+ for (int i = 0; i < DECODE_ITERATIONS; i++) {
+ BitmapFactory.decodeResource(mResources, R.drawable.test16x12);
+ BitmapFactory.decodeResource(mResources, R.drawable.test32x24);
+ BitmapFactory.decodeResource(mResources, R.drawable.test64x48);
+ BitmapFactory.decodeResource(mResources, R.drawable.test128x96);
+ BitmapFactory.decodeResource(mResources, R.drawable.test256x192);
+ BitmapFactory.decodeResource(mResources, R.drawable.test320x240);
+ }
+ }
+ }
+
+ /**
+ * Base class for bitmap drawing tests
+ *
+ */
+ public static abstract class DrawBitmapTest extends GraphicsTestBase {
+ /** Number of times to run each draw test */
+ private static final int ITERATIONS = 1000;
+
+ /** Bitmap to draw. Allocated by subclass's createBitmap() function. */
+ private Bitmap mBitmap;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+
+ // Invoke subclass's method to create the bitmap
+ mBitmap = createBitmap();
+ }
+
+ public int getIterations() {
+ return ITERATIONS;
+ }
+
+ // Generic abstract function to create bitmap for any given subclass
+ public abstract Bitmap createBitmap();
+
+ // Provide convenience test code for all subsequent classes.
+ // Note: Though it would be convenient to declare all of the test*() methods here
+ // and just inherit them, our test harness doesn't support it. So we replicate
+ // a bit of code in each derived test case.
+ public void drawBitmapEven() {
+ for (int i = 0; i < ITERATIONS; i++) {
+ mCanvas.drawBitmap(mBitmap, 0.0f, 0.0f, mPaint);
+ }
+ }
+
+ public void drawBitmapOdd() {
+ for (int i = 0; i < ITERATIONS; i++) {
+ mCanvas.drawBitmap(mBitmap, 1.0f, 0.0f, mPaint);
+ }
+ }
+ }
+
+
+ /**
+ * Test drawing of 7x7 image
+ */
+ public static class DrawBitmap7x7 extends DrawBitmapTest {
+
+ public Bitmap createBitmap() {
+ return Bitmap.createBitmap(7, 7, Bitmap.Config.RGB_565);
+ }
+
+ public void testDrawBitmapEven() {
+ drawBitmapEven();
+ }
+
+ public void testDrawBitmapOdd() {
+ drawBitmapOdd();
+ }
+ }
+
+ /**
+ * Test drawing of 15x15 image
+ */
+ public static class DrawBitmap15x15 extends DrawBitmapTest {
+
+ public Bitmap createBitmap() {
+ return Bitmap.createBitmap(15, 15, Bitmap.Config.RGB_565);
+ }
+
+ public void testDrawBitmapEven() {
+ drawBitmapEven();
+ }
+
+ public void testDrawBitmapOdd() {
+ drawBitmapOdd();
+ }
+ }
+
+ /**
+ * Test drawing of 31x31 image
+ */
+ public static class DrawBitmap31x31 extends DrawBitmapTest {
+
+ public Bitmap createBitmap() {
+ return Bitmap.createBitmap(31, 31, Bitmap.Config.RGB_565);
+ }
+
+ public void testDrawBitmapEven() {
+ drawBitmapEven();
+ }
+
+ public void testDrawBitmapOdd() {
+ drawBitmapOdd();
+ }
+ }
+
+ /**
+ * Test drawing of 63x63 image
+ */
+ public static class DrawBitmap63x63 extends DrawBitmapTest {
+
+ public Bitmap createBitmap() {
+ return Bitmap.createBitmap(63, 63, Bitmap.Config.RGB_565);
+ }
+
+ public void testDrawBitmapEven() {
+ drawBitmapEven();
+ }
+
+ public void testDrawBitmapOdd() {
+ drawBitmapOdd();
+ }
+ }
+
+ /**
+ * Test drawing of 127x127 image
+ */
+ public static class DrawBitmap127x127 extends DrawBitmapTest {
+
+ public Bitmap createBitmap() {
+ return Bitmap.createBitmap(127, 127, Bitmap.Config.RGB_565);
+ }
+
+ public void testDrawBitmapEven() {
+ drawBitmapEven();
+ }
+
+ public void testDrawBitmapOdd() {
+ drawBitmapOdd();
+ }
+ }
+
+ /**
+ * Test drawing of 319x239 image
+ */
+ public static class DrawBitmap319x239 extends DrawBitmapTest {
+
+ public Bitmap createBitmap() {
+ return Bitmap.createBitmap(319, 239, Bitmap.Config.RGB_565);
+ }
+
+ public void testDrawBitmapEven() {
+ drawBitmapEven();
+ }
+
+ public void testDrawBitmapOdd() {
+ drawBitmapOdd();
+ }
+ }
+
+ /**
+ * Test drawing of 319x479 image
+ */
+ public static class DrawBitmap319x479 extends DrawBitmapTest {
+
+ public Bitmap createBitmap() {
+ return Bitmap.createBitmap(319, 479, Bitmap.Config.RGB_565);
+ }
+
+ public void testDrawBitmapEven() {
+ drawBitmapEven();
+ }
+
+ public void testDrawBitmapOdd() {
+ drawBitmapOdd();
+ }
+ }
+
+ /**
+ * Test drawing of 8x8 image
+ */
+ public static class DrawBitmap8x8 extends DrawBitmapTest {
+
+ public Bitmap createBitmap() {
+ return Bitmap.createBitmap(8, 8, Bitmap.Config.RGB_565);
+ }
+
+ public void testDrawBitmapEven() {
+ drawBitmapEven();
+ }
+
+ public void testDrawBitmapOdd() {
+ drawBitmapOdd();
+ }
+ }
+
+ /**
+ * Test drawing of 16x16 image
+ */
+ public static class DrawBitmap16x16 extends DrawBitmapTest {
+
+ public Bitmap createBitmap() {
+ return Bitmap.createBitmap(16, 16, Bitmap.Config.RGB_565);
+ }
+
+ public void testDrawBitmapEven() {
+ drawBitmapEven();
+ }
+
+ public void testDrawBitmapOdd() {
+ drawBitmapOdd();
+ }
+ }
+
+ /**
+ * Test drawing of 32x32 image
+ */
+ public static class DrawBitmap32x32 extends DrawBitmapTest {
+
+ public Bitmap createBitmap() {
+ return Bitmap.createBitmap(32, 32, Bitmap.Config.RGB_565);
+ }
+
+ public void testDrawBitmapEven() {
+ drawBitmapEven();
+ }
+
+ public void testDrawBitmapOdd() {
+ drawBitmapOdd();
+ }
+ }
+
+ /**
+ * Test drawing of 64x64 image
+ */
+ public static class DrawBitmap64x64 extends DrawBitmapTest {
+
+ public Bitmap createBitmap() {
+ return Bitmap.createBitmap(64, 64, Bitmap.Config.RGB_565);
+ }
+
+ public void testDrawBitmapEven() {
+ drawBitmapEven();
+ }
+
+ public void testDrawBitmapOdd() {
+ drawBitmapOdd();
+ }
+ }
+
+ /**
+ * Test drawing of 128x128 image
+ */
+ public static class DrawBitmap128x128 extends DrawBitmapTest {
+
+ public Bitmap createBitmap() {
+ return Bitmap.createBitmap(128, 128, Bitmap.Config.RGB_565);
+ }
+
+ public void testDrawBitmapEven() {
+ drawBitmapEven();
+ }
+
+ public void testDrawBitmapOdd() {
+ drawBitmapOdd();
+ }
+ }
+
+ /**
+ * Test drawing of 320x240 image
+ */
+ public static class DrawBitmap320x240 extends DrawBitmapTest {
+
+ public Bitmap createBitmap() {
+ return Bitmap.createBitmap(320, 240, Bitmap.Config.RGB_565);
+ }
+
+ public void testDrawBitmapEven() {
+ drawBitmapEven();
+ }
+
+ public void testDrawBitmapOdd() {
+ drawBitmapOdd();
+ }
+ }
+
+ /**
+ * Test drawing of 320x480 image
+ */
+ public static class DrawBitmap320x480 extends DrawBitmapTest {
+
+ public Bitmap createBitmap() {
+ return Bitmap.createBitmap(320, 480, Bitmap.Config.RGB_565);
+ }
+
+ public void testDrawBitmapEven() {
+ drawBitmapEven();
+ }
+
+ public void testDrawBitmapOdd() {
+ drawBitmapOdd();
+ }
+ }
+}
diff --git a/graphics/tests/graphicstests/src/android/graphics/GraphicsTests.java b/graphics/tests/graphicstests/src/android/graphics/GraphicsTests.java
new file mode 100644
index 0000000..8d01ea7
--- /dev/null
+++ b/graphics/tests/graphicstests/src/android/graphics/GraphicsTests.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.graphics;
+
+import junit.framework.TestSuite;
+
+public class GraphicsTests {
+ public static TestSuite suite() {
+ TestSuite suite = new TestSuite(GraphicsTests.class.getName());
+
+ suite.addTestSuite(BitmapTest.class);
+ suite.addTestSuite(TypefaceTest.class);
+ return suite;
+ }
+}
diff --git a/graphics/tests/graphicstests/src/android/graphics/ThreadBitmapTest.java b/graphics/tests/graphicstests/src/android/graphics/ThreadBitmapTest.java
new file mode 100644
index 0000000..84bdc56
--- /dev/null
+++ b/graphics/tests/graphicstests/src/android/graphics/ThreadBitmapTest.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.graphics;
+
+import junit.framework.TestCase;
+import android.graphics.Bitmap;
+import android.test.suitebuilder.annotation.LargeTest;
+
+public class ThreadBitmapTest extends TestCase {
+
+ @Override
+ protected void setUp() throws Exception {
+ }
+
+ @LargeTest
+ public void testCreation() {
+ for (int i = 0; i < 200; i++) {
+
+ new MThread().start();
+ }
+ }
+
+ class MThread extends Thread {
+ public Bitmap b;
+
+ public MThread() {
+ b = Bitmap.createBitmap(300, 300, Bitmap.Config.RGB_565);
+ }
+
+ public void run() {}
+ }
+}
+
diff --git a/graphics/tests/graphicstests/src/android/graphics/TypefaceTest.java b/graphics/tests/graphicstests/src/android/graphics/TypefaceTest.java
new file mode 100644
index 0000000..334fddf
--- /dev/null
+++ b/graphics/tests/graphicstests/src/android/graphics/TypefaceTest.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.graphics;
+
+import android.graphics.Paint;
+import android.graphics.Typeface;
+import android.test.suitebuilder.annotation.MediumTest;
+import android.test.suitebuilder.annotation.SmallTest;
+import junit.framework.TestCase;
+
+
+public class TypefaceTest extends TestCase {
+
+ // create array of all std faces
+ private final Typeface[] mFaces = new Typeface[] {
+ Typeface.create(Typeface.SANS_SERIF, 0),
+ Typeface.create(Typeface.SANS_SERIF, 1),
+ Typeface.create(Typeface.SERIF, 0),
+ Typeface.create(Typeface.SERIF, 1),
+ Typeface.create(Typeface.SERIF, 2),
+ Typeface.create(Typeface.SERIF, 3),
+ Typeface.create(Typeface.MONOSPACE, 0)
+ };
+
+ @SmallTest
+ public void testBasic() throws Exception {
+ assertTrue("basic", Typeface.DEFAULT != null);
+ assertTrue("basic", Typeface.DEFAULT_BOLD != null);
+ assertTrue("basic", Typeface.SANS_SERIF != null);
+ assertTrue("basic", Typeface.SERIF != null);
+ assertTrue("basic", Typeface.MONOSPACE != null);
+ }
+
+ @SmallTest
+ public void testUnique() throws Exception {
+ final int n = mFaces.length;
+ for (int i = 0; i < n; i++) {
+ for (int j = i + 1; j < n; j++) {
+ assertTrue("unique", mFaces[i] != mFaces[j]);
+ }
+ }
+ }
+
+ @SmallTest
+ public void testStyles() throws Exception {
+ assertTrue("style", mFaces[0].getStyle() == Typeface.NORMAL);
+ assertTrue("style", mFaces[1].getStyle() == Typeface.BOLD);
+ assertTrue("style", mFaces[2].getStyle() == Typeface.NORMAL);
+ assertTrue("style", mFaces[3].getStyle() == Typeface.BOLD);
+ assertTrue("style", mFaces[4].getStyle() == Typeface.ITALIC);
+ assertTrue("style", mFaces[5].getStyle() == Typeface.BOLD_ITALIC);
+ assertTrue("style", mFaces[6].getStyle() == Typeface.NORMAL);
+ }
+
+ @MediumTest
+ public void testUniformY() throws Exception {
+ Paint p = new Paint();
+ final int n = mFaces.length;
+ for (int i = 1; i <= 36; i++) {
+ p.setTextSize(i);
+ float ascent = 0;
+ float descent = 0;
+ for (int j = 0; j < n; j++) {
+ p.setTypeface(mFaces[j]);
+ Paint.FontMetrics fm = p.getFontMetrics();
+ if (j == 0) {
+ ascent = fm.ascent;
+ descent = fm.descent;
+ } else {
+ assertTrue("fontMetrics", fm.ascent == ascent);
+ assertTrue("fontMetrics", fm.descent == descent);
+ }
+ }
+ }
+ }
+
+}