diff options
Diffstat (limited to 'graphics/java')
42 files changed, 1346 insertions, 407 deletions
diff --git a/graphics/java/android/graphics/AvoidXfermode.java b/graphics/java/android/graphics/AvoidXfermode.java index 7e2722d..5a59e36 100644 --- a/graphics/java/android/graphics/AvoidXfermode.java +++ b/graphics/java/android/graphics/AvoidXfermode.java @@ -20,6 +20,7 @@ package android.graphics; * AvoidXfermode xfermode will draw the src everywhere except on top of the * opColor or, depending on the Mode, draw only on top of the opColor. */ +@Deprecated public class AvoidXfermode extends Xfermode { // these need to match the enum in SkAvoidXfermode.h on the native side diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java index 380b3d8..c726d0e 100644 --- a/graphics/java/android/graphics/Bitmap.java +++ b/graphics/java/android/graphics/Bitmap.java @@ -19,6 +19,7 @@ package android.graphics; import android.os.Parcel; import android.os.Parcelable; import android.util.DisplayMetrics; + import java.io.OutputStream; import java.nio.Buffer; import java.nio.ByteBuffer; @@ -57,6 +58,7 @@ public final class Bitmap implements Parcelable { private final boolean mIsMutable; private byte[] mNinePatchChunk; // may be null + private int[] mLayoutBounds; // may be null private int mWidth = -1; private int mHeight = -1; private boolean mRecycled; @@ -95,6 +97,19 @@ public final class Bitmap implements Parcelable { */ /*package*/ Bitmap(int nativeBitmap, byte[] buffer, boolean isMutable, byte[] ninePatchChunk, int density) { + this(nativeBitmap, buffer, isMutable, ninePatchChunk, null, density); + } + + /** + * @noinspection UnusedDeclaration + */ + /* Private constructor that must received an already allocated native + bitmap int (pointer). + + This can be called from JNI code. + */ + /*package*/ Bitmap(int nativeBitmap, byte[] buffer, boolean isMutable, byte[] ninePatchChunk, + int[] layoutBounds, int density) { if (nativeBitmap == 0) { throw new RuntimeException("internal error: native bitmap is 0"); } @@ -106,6 +121,7 @@ public final class Bitmap implements Parcelable { mIsMutable = isMutable; mNinePatchChunk = ninePatchChunk; + mLayoutBounds = layoutBounds; if (density >= 0) { mDensity = density; } @@ -164,6 +180,16 @@ public final class Bitmap implements Parcelable { } /** + * Sets the layout bounds as an array of left, top, right, bottom integers + * @param bounds the array containing the padding values + * + * @hide + */ + public void setLayoutBounds(int[] bounds) { + mLayoutBounds = bounds; + } + + /** * Free the native object associated with this bitmap, and clear the * reference to the pixel data. This will not free the pixel data synchronously; * it simply allows it to be garbage collected if there are no other references. @@ -408,16 +434,19 @@ public final class Bitmap implements Parcelable { } /** - * Creates a new bitmap, scaled from an existing bitmap. + * Creates a new bitmap, scaled from an existing bitmap, when possible. If the + * specified width and height are the same as the current width and height of + * the source btimap, the source bitmap is returned and now new bitmap is + * created. * * @param src The source bitmap. * @param dstWidth The new bitmap's desired width. * @param dstHeight The new bitmap's desired height. * @param filter true if the source should be filtered. - * @return the new scaled bitmap. + * @return The new scaled bitmap or the source bitmap if no scaling is required. */ - public static Bitmap createScaledBitmap(Bitmap src, int dstWidth, - int dstHeight, boolean filter) { + public static Bitmap createScaledBitmap(Bitmap src, int dstWidth, int dstHeight, + boolean filter) { Matrix m; synchronized (Bitmap.class) { // small pool of just 1 matrix @@ -458,14 +487,15 @@ public final class Bitmap implements Parcelable { /** * Returns an immutable bitmap from the specified subset of the source * bitmap. The new bitmap may be the same object as source, or a copy may - * have been made. It is - * initialized with the same density as the original bitmap. + * have been made. It is initialized with the same density as the original + * bitmap. * * @param source The bitmap we are subsetting * @param x The x coordinate of the first pixel in source * @param y The y coordinate of the first pixel in source * @param width The number of pixels in each row * @param height The number of rows + * @return A copy of a subset of the source bitmap or the source bitmap itself. */ public static Bitmap createBitmap(Bitmap source, int x, int y, int width, int height) { return createBitmap(source, x, y, width, height, null, false); @@ -473,8 +503,13 @@ public final class Bitmap implements Parcelable { /** * Returns an immutable bitmap from subset of the source bitmap, - * transformed by the optional matrix. It is + * transformed by the optional matrix. The new bitmap may be the + * same object as source, or a copy may have been made. It is * initialized with the same density as the original bitmap. + * + * If the source bitmap is immutable and the requested subset is the + * same as the source bitmap itself, then the source bitmap is + * returned and no new bitmap is created. * * @param source The bitmap we are subsetting * @param x The x coordinate of the first pixel in source @@ -681,6 +716,14 @@ public final class Bitmap implements Parcelable { } /** + * @hide + * @return the layout padding [left, right, top, bottom] + */ + public int[] getLayoutBounds() { + return mLayoutBounds; + } + + /** * Specifies the known formats a bitmap can be compressed into */ public enum CompressFormat { diff --git a/graphics/java/android/graphics/BitmapFactory.java b/graphics/java/android/graphics/BitmapFactory.java index 8d17561..1599e40 100644 --- a/graphics/java/android/graphics/BitmapFactory.java +++ b/graphics/java/android/graphics/BitmapFactory.java @@ -32,6 +32,8 @@ import java.io.InputStream; * and byte-arrays. */ public class BitmapFactory { + private static final int DECODE_BUFFER_SIZE = 16 * 1024; + public static class Options { /** * Create a default Options object, which if left unchanged will give @@ -422,6 +424,7 @@ public class BitmapFactory { throw new ArrayIndexOutOfBoundsException(); } Bitmap bm = nativeDecodeByteArray(data, offset, length, opts); + if (bm == null && opts != null && opts.inBitmap != null) { throw new IllegalArgumentException("Problem decoding into existing bitmap"); } @@ -469,7 +472,7 @@ public class BitmapFactory { // we need mark/reset to work properly if (!is.markSupported()) { - is = new BufferedInputStream(is, 16 * 1024); + is = new BufferedInputStream(is, DECODE_BUFFER_SIZE); } // so we can call reset() if a given codec gives up after reading up to @@ -477,11 +480,30 @@ public class BitmapFactory { // value should be. is.mark(1024); - Bitmap bm; + Bitmap bm; + boolean finish = true; if (is instanceof AssetManager.AssetInputStream) { - bm = nativeDecodeAsset(((AssetManager.AssetInputStream) is).getAssetInt(), - outPadding, opts); + final int asset = ((AssetManager.AssetInputStream) is).getAssetInt(); + + if (opts == null || (opts.inScaled && opts.inBitmap == null)) { + float scale = 1.0f; + int targetDensity = 0; + if (opts != null) { + final int density = opts.inDensity; + targetDensity = opts.inTargetDensity; + if (density != 0 && targetDensity != 0) { + scale = targetDensity / (float) density; + } + } + + bm = nativeDecodeAsset(asset, outPadding, opts, true, scale); + if (bm != null && targetDensity != 0) bm.setDensity(targetDensity); + + finish = false; + } else { + bm = nativeDecodeAsset(asset, outPadding, opts); + } } else { // pass some temp storage down to the native code. 1024 is made up, // but should be large enough to avoid too many small calls back @@ -490,13 +512,32 @@ public class BitmapFactory { byte [] tempStorage = null; if (opts != null) tempStorage = opts.inTempStorage; if (tempStorage == null) tempStorage = new byte[16 * 1024]; - bm = nativeDecodeStream(is, tempStorage, outPadding, opts); + + if (opts == null || (opts.inScaled && opts.inBitmap == null)) { + float scale = 1.0f; + int targetDensity = 0; + if (opts != null) { + final int density = opts.inDensity; + targetDensity = opts.inTargetDensity; + if (density != 0 && targetDensity != 0) { + scale = targetDensity / (float) density; + } + } + + bm = nativeDecodeStream(is, tempStorage, outPadding, opts, true, scale); + if (bm != null && targetDensity != 0) bm.setDensity(targetDensity); + + finish = false; + } else { + bm = nativeDecodeStream(is, tempStorage, outPadding, opts); + } } + if (bm == null && opts != null && opts.inBitmap != null) { throw new IllegalArgumentException("Problem decoding into existing bitmap"); } - return finishDecode(bm, outPadding, opts); + return finish ? finishDecode(bm, outPadding, opts) : bm; } private static Bitmap finishDecode(Bitmap bm, Rect outPadding, Options opts) { @@ -514,21 +555,22 @@ public class BitmapFactory { if (targetDensity == 0 || density == targetDensity || density == opts.inScreenDensity) { return bm; } - byte[] np = bm.getNinePatchChunk(); final boolean isNinePatch = np != null && NinePatch.isNinePatchChunk(np); if (opts.inScaled || isNinePatch) { - float scale = targetDensity / (float)density; - // TODO: This is very inefficient and should be done in native by Skia - final Bitmap oldBitmap = bm; - bm = Bitmap.createScaledBitmap(oldBitmap, (int) (bm.getWidth() * scale + 0.5f), - (int) (bm.getHeight() * scale + 0.5f), true); - oldBitmap.recycle(); - - if (isNinePatch) { - np = nativeScaleNinePatch(np, scale, outPadding); - bm.setNinePatchChunk(np); + float scale = targetDensity / (float) density; + if (scale != 1.0f) { + final Bitmap oldBitmap = bm; + bm = Bitmap.createScaledBitmap(oldBitmap, (int) (bm.getWidth() * scale + 0.5f), + (int) (bm.getHeight() * scale + 0.5f), true); + if (bm != oldBitmap) oldBitmap.recycle(); + + if (isNinePatch) { + np = nativeScaleNinePatch(np, scale, outPadding); + bm.setNinePatchChunk(np); + } } + bm.setDensity(targetDensity); } @@ -594,35 +636,15 @@ 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 nativeDecodeStream(InputStream is, byte[] storage, + Rect padding, Options opts, boolean applyScale, float scale); private static native Bitmap nativeDecodeFileDescriptor(FileDescriptor fd, Rect padding, Options opts); private static native Bitmap nativeDecodeAsset(int asset, Rect padding, Options opts); + private static native Bitmap nativeDecodeAsset(int asset, Rect padding, Options opts, + boolean applyScale, float scale); private static native Bitmap nativeDecodeByteArray(byte[] data, int offset, int length, Options opts); private static native byte[] nativeScaleNinePatch(byte[] chunk, float scale, Rect pad); diff --git a/graphics/java/android/graphics/Camera.java b/graphics/java/android/graphics/Camera.java index 7ef35a9..6f71a2b 100644 --- a/graphics/java/android/graphics/Camera.java +++ b/graphics/java/android/graphics/Camera.java @@ -100,6 +100,27 @@ public class Camera { public native void rotate(float x, float y, float z); /** + * Gets the x location of the camera. + * + * @see #setLocation(float, float, float) + */ + public native float getLocationX(); + + /** + * Gets the y location of the camera. + * + * @see #setLocation(float, float, float) + */ + public native float getLocationY(); + + /** + * Gets the z location of the camera. + * + * @see #setLocation(float, float, float) + */ + public native float getLocationZ(); + + /** * Sets the location of the camera. The default location is set at * 0, 0, -8. * diff --git a/graphics/java/android/graphics/Canvas.java b/graphics/java/android/graphics/Canvas.java index e1c73fd..7e92973 100644 --- a/graphics/java/android/graphics/Canvas.java +++ b/graphics/java/android/graphics/Canvas.java @@ -40,14 +40,8 @@ public class Canvas { // assigned in constructors, freed in finalizer final int mNativeCanvas; - /* Our native canvas can be either a raster, gl, or picture canvas. - If we are raster, then mGL will be null, and mBitmap may or may not be - present (our default constructor creates a raster canvas but no - java-bitmap is). If we are a gl-based, then mBitmap will be null, and - mGL will not be null. Thus both cannot be non-null, but its possible - for both to be null. - */ - private Bitmap mBitmap; // if not null, mGL must be null + // may be null + private Bitmap mBitmap; // optional field set by the caller private DrawFilter mDrawFilter; @@ -66,7 +60,7 @@ public class Canvas { // Used by native code @SuppressWarnings({"UnusedDeclaration"}) - private int mSurfaceFormat; + private int mSurfaceFormat; /** * Flag for drawTextRun indicating left-to-right run direction. @@ -130,8 +124,7 @@ public class Canvas { */ public Canvas(Bitmap bitmap) { if (!bitmap.isMutable()) { - throw new IllegalStateException( - "Immutable bitmap passed to Canvas constructor"); + throw new IllegalStateException("Immutable bitmap passed to Canvas constructor"); } throwIfRecycled(bitmap); mNativeCanvas = initRaster(bitmap.ni()); @@ -361,8 +354,8 @@ public class Canvas { /** * Helper version of saveLayer() that takes 4 values rather than a RectF. */ - public int saveLayer(float left, float top, float right, float bottom, - Paint paint, int saveFlags) { + public int saveLayer(float left, float top, float right, float bottom, Paint paint, + int saveFlags) { return native_saveLayer(mNativeCanvas, left, top, right, bottom, paint != null ? paint.mNativePaint : 0, saveFlags); @@ -392,8 +385,8 @@ public class Canvas { /** * Helper for saveLayerAlpha() that takes 4 values instead of a RectF. */ - public int saveLayerAlpha(float left, float top, float right, float bottom, - int alpha, int saveFlags) { + public int saveLayerAlpha(float left, float top, float right, float bottom, int alpha, + int saveFlags) { return native_saveLayerAlpha(mNativeCanvas, left, top, right, bottom, alpha, saveFlags); } @@ -496,9 +489,15 @@ public class Canvas { /** * Completely replace the current matrix with the specified matrix. If the * matrix parameter is null, then the current matrix is reset to identity. + * + * <strong>Note:</strong> it is recommended to use {@link #concat(Matrix)}, + * {@link #scale(float, float)}, {@link #translate(float, float)} and + * {@link #rotate(float)} instead of this method. * * @param matrix The matrix to replace the current matrix with. If it is * null, set the current matrix to identity. + * + * @see #concat(Matrix) */ public void setMatrix(Matrix matrix) { native_setMatrix(mNativeCanvas, @@ -509,6 +508,7 @@ public class Canvas { * Return, in ctm, the current transformation matrix. This does not alter * the matrix in the canvas, but just returns a copy of it. */ + @Deprecated public void getMatrix(Matrix ctm) { native_getCTM(mNativeCanvas, ctm.native_instance); } @@ -517,8 +517,10 @@ public class Canvas { * Return a new matrix with a copy of the canvas' current transformation * matrix. */ + @Deprecated public final Matrix getMatrix() { Matrix m = new Matrix(); + //noinspection deprecation getMatrix(m); return m; } @@ -531,9 +533,8 @@ public class Canvas { * @return true if the resulting clip is non-empty */ public boolean clipRect(RectF rect, Region.Op op) { - return native_clipRect(mNativeCanvas, - rect.left, rect.top, rect.right, rect.bottom, - op.nativeInt); + return native_clipRect(mNativeCanvas, rect.left, rect.top, rect.right, rect.bottom, + op.nativeInt); } /** @@ -545,9 +546,8 @@ public class Canvas { * @return true if the resulting clip is non-empty */ public boolean clipRect(Rect rect, Region.Op op) { - return native_clipRect(mNativeCanvas, - rect.left, rect.top, rect.right, rect.bottom, - op.nativeInt); + return native_clipRect(mNativeCanvas, rect.left, rect.top, rect.right, rect.bottom, + op.nativeInt); } /** @@ -583,10 +583,8 @@ public class Canvas { * @param op How the clip is modified * @return true if the resulting clip is non-empty */ - public boolean clipRect(float left, float top, float right, float bottom, - Region.Op op) { - return native_clipRect(mNativeCanvas, left, top, right, bottom, - op.nativeInt); + public boolean clipRect(float left, float top, float right, float bottom, Region.Op op) { + return native_clipRect(mNativeCanvas, left, top, right, bottom, op.nativeInt); } /** @@ -602,9 +600,8 @@ public class Canvas { * clip * @return true if the resulting clip is non-empty */ - public native boolean clipRect(float left, float top, - float right, float bottom); - + public native boolean clipRect(float left, float top, float right, float bottom); + /** * Intersect the current clip with the specified rectangle, which is * expressed in local coordinates. @@ -618,9 +615,8 @@ public class Canvas { * clip * @return true if the resulting clip is non-empty */ - public native boolean clipRect(int left, int top, - int right, int bottom); - + public native boolean clipRect(int left, int top, int right, int bottom); + /** * Modify the current clip with the specified path. * @@ -753,8 +749,7 @@ public class Canvas { * @return true if the rect (transformed by the canvas' matrix) * does not intersect with the canvas' clip */ - public boolean quickReject(float left, float top, float right, float bottom, - EdgeType type) { + public boolean quickReject(float left, float top, float right, float bottom, EdgeType type) { return native_quickReject(mNativeCanvas, left, top, right, bottom, type.nativeInt); } @@ -854,8 +849,7 @@ public class Canvas { * "points" that are drawn is really (count >> 1). * @param paint The paint used to draw the points */ - public native void drawPoints(float[] pts, int offset, int count, - Paint paint); + public native void drawPoints(float[] pts, int offset, int count, Paint paint); /** * Helper for drawPoints() that assumes you want to draw the entire array @@ -878,10 +872,8 @@ public class Canvas { * @param startY The y-coordinate of the start point of the line * @param paint The paint used to draw the line */ - public void drawLine(float startX, float startY, float stopX, float stopY, - Paint paint) { - native_drawLine(mNativeCanvas, startX, startY, stopX, stopY, - paint.mNativePaint); + public void drawLine(float startX, float startY, float stopX, float stopY, Paint paint) { + native_drawLine(mNativeCanvas, startX, startY, stopX, stopY, paint.mNativePaint); } /** @@ -899,8 +891,7 @@ public class Canvas { * (count >> 2). * @param paint The paint used to draw the points */ - public native void drawLines(float[] pts, int offset, int count, - Paint paint); + public native void drawLines(float[] pts, int offset, int count, Paint paint); public void drawLines(float[] pts, Paint paint) { drawLines(pts, 0, pts.length, paint); @@ -939,10 +930,8 @@ public class Canvas { * @param bottom The bottom side of the rectangle to be drawn * @param paint The paint used to draw the rect */ - public void drawRect(float left, float top, float right, float bottom, - Paint paint) { - native_drawRect(mNativeCanvas, left, top, right, bottom, - paint.mNativePaint); + public void drawRect(float left, float top, float right, float bottom, Paint paint) { + native_drawRect(mNativeCanvas, left, top, right, bottom, paint.mNativePaint); } /** @@ -969,8 +958,7 @@ public class Canvas { * @param paint The paint used to draw the circle */ public void drawCircle(float cx, float cy, float radius, Paint paint) { - native_drawCircle(mNativeCanvas, cx, cy, radius, - paint.mNativePaint); + native_drawCircle(mNativeCanvas, cx, cy, radius, paint.mNativePaint); } /** @@ -996,8 +984,8 @@ public class Canvas { close it if it is being stroked. This will draw a wedge * @param paint The paint used to draw the arc */ - public void drawArc(RectF oval, float startAngle, float sweepAngle, - boolean useCenter, Paint paint) { + public void drawArc(RectF oval, float startAngle, float sweepAngle, boolean useCenter, + Paint paint) { if (oval == null) { throw new NullPointerException(); } @@ -1035,8 +1023,7 @@ public class Canvas { private static void throwIfRecycled(Bitmap bitmap) { if (bitmap.isRecycled()) { - throw new RuntimeException( - "Canvas: trying to use a recycled bitmap " + bitmap); + throw new RuntimeException("Canvas: trying to use a recycled bitmap " + bitmap); } } @@ -1077,8 +1064,7 @@ public class Canvas { public void drawBitmap(Bitmap bitmap, float left, float top, Paint paint) { throwIfRecycled(bitmap); native_drawBitmap(mNativeCanvas, bitmap.ni(), left, top, - paint != null ? paint.mNativePaint : 0, mDensity, mScreenDensity, - bitmap.mDensity); + paint != null ? paint.mNativePaint : 0, mDensity, mScreenDensity, bitmap.mDensity); } /** @@ -1109,8 +1095,7 @@ public class Canvas { } throwIfRecycled(bitmap); native_drawBitmap(mNativeCanvas, bitmap.ni(), src, dst, - paint != null ? paint.mNativePaint : 0, - mScreenDensity, bitmap.mDensity); + paint != null ? paint.mNativePaint : 0, mScreenDensity, bitmap.mDensity); } /** @@ -1141,8 +1126,7 @@ public class Canvas { } throwIfRecycled(bitmap); native_drawBitmap(mNativeCanvas, bitmap.ni(), src, dst, - paint != null ? paint.mNativePaint : 0, - mScreenDensity, bitmap.mDensity); + paint != null ? paint.mNativePaint : 0, mScreenDensity, bitmap.mDensity); } /** @@ -1164,9 +1148,8 @@ public class Canvas { * be 0xFF for every pixel). * @param paint May be null. The paint used to draw the bitmap */ - public void drawBitmap(int[] colors, int offset, int stride, float x, - float y, int width, int height, boolean hasAlpha, - Paint paint) { + public void drawBitmap(int[] colors, int offset, int stride, float x, float y, + int width, int height, boolean hasAlpha, Paint paint) { // check for valid input if (width < 0) { throw new IllegalArgumentException("width must be >= 0"); @@ -1195,8 +1178,7 @@ public class Canvas { /** Legacy version of drawBitmap(int[] colors, ...) that took ints for x,y */ public void drawBitmap(int[] colors, int offset, int stride, int x, int y, - int width, int height, boolean hasAlpha, - Paint paint) { + int width, int height, boolean hasAlpha, Paint paint) { // call through to the common float version drawBitmap(colors, offset, stride, (float)x, (float)y, width, height, hasAlpha, paint); @@ -1250,8 +1232,7 @@ public class Canvas { * @param paint May be null. The paint used to draw the bitmap */ public void drawBitmapMesh(Bitmap bitmap, int meshWidth, int meshHeight, - float[] verts, int vertOffset, - int[] colors, int colorOffset, Paint paint) { + float[] verts, int vertOffset, int[] colors, int colorOffset, Paint paint) { if ((meshWidth | meshHeight | vertOffset | colorOffset) < 0) { throw new ArrayIndexOutOfBoundsException(); } @@ -1269,7 +1250,7 @@ public class Canvas { verts, vertOffset, colors, colorOffset, paint != null ? paint.mNativePaint : 0); } - + public enum VertexMode { TRIANGLES(0), TRIANGLE_STRIP(1), @@ -1315,12 +1296,9 @@ public class Canvas { * @param indexCount number of entries in the indices array (if not null). * @param paint Specifies the shader to use if the texs array is non-null. */ - public void drawVertices(VertexMode mode, int vertexCount, - float[] verts, int vertOffset, - float[] texs, int texOffset, - int[] colors, int colorOffset, - short[] indices, int indexOffset, - int indexCount, Paint paint) { + public void drawVertices(VertexMode mode, int vertexCount, float[] verts, int vertOffset, + float[] texs, int texOffset, int[] colors, int colorOffset, + short[] indices, int indexOffset, int indexCount, Paint paint) { checkRange(verts.length, vertOffset, vertexCount); if (texs != null) { checkRange(texs.length, texOffset, vertexCount); @@ -1345,8 +1323,7 @@ public class Canvas { * @param y The y-coordinate of the origin of the text being drawn * @param paint The paint used for the text (e.g. color, size, style) */ - public void drawText(char[] text, int index, int count, float x, float y, - Paint paint) { + public void drawText(char[] text, int index, int count, float x, float y, Paint paint) { if ((index | count | (index + count) | (text.length - index - count)) < 0) { throw new IndexOutOfBoundsException(); @@ -1380,8 +1357,7 @@ public class Canvas { * @param y The y-coordinate of the origin of the text being drawn * @param paint The paint used for the text (e.g. color, size, style) */ - public void drawText(String text, int start, int end, float x, float y, - Paint paint) { + public void drawText(String text, int start, int end, float x, float y, Paint paint) { if ((start | end | (end - start) | (text.length() - end)) < 0) { throw new IndexOutOfBoundsException(); } @@ -1402,8 +1378,7 @@ public class Canvas { * @param y The y-coordinate of origin for where to draw the text * @param paint The paint used for the text (e.g. color, size, style) */ - public void drawText(CharSequence text, int start, int end, float x, - float y, Paint paint) { + public void drawText(CharSequence text, int start, int end, float x, float y, Paint paint) { if (text instanceof String || text instanceof SpannedString || text instanceof SpannableString) { native_drawText(mNativeCanvas, text.toString(), start, end, x, y, @@ -1441,9 +1416,8 @@ public class Canvas { * @param paint the paint * @hide */ - public void drawTextRun(char[] text, int index, int count, - int contextIndex, int contextCount, float x, float y, int dir, - Paint paint) { + public void drawTextRun(char[] text, int index, int count, int contextIndex, int contextCount, + float x, float y, int dir, Paint paint) { if (text == null) { throw new NullPointerException("text is null"); @@ -1479,9 +1453,8 @@ public class Canvas { * @param paint the paint * @hide */ - public void drawTextRun(CharSequence text, int start, int end, - int contextStart, int contextEnd, float x, float y, int dir, - Paint paint) { + public void drawTextRun(CharSequence text, int start, int end, int contextStart, int contextEnd, + float x, float y, int dir, Paint paint) { if (text == null) { throw new NullPointerException("text is null"); @@ -1516,6 +1489,9 @@ public class Canvas { /** * Draw the text in the array, with each character's origin specified by * the pos array. + * + * This method does not support glyph composition and decomposition and + * should therefore not be used to render complex scripts. * * @param text The text to be drawn * @param index The index of the first character to draw @@ -1524,8 +1500,8 @@ public class Canvas { * character * @param paint The paint used for the text (e.g. color, size, style) */ - public void drawPosText(char[] text, int index, int count, float[] pos, - Paint paint) { + @Deprecated + public void drawPosText(char[] text, int index, int count, float[] pos, Paint paint) { if (index < 0 || index + count > text.length || count*2 > pos.length) { throw new IndexOutOfBoundsException(); } @@ -1536,11 +1512,15 @@ public class Canvas { /** * Draw the text in the array, with each character's origin specified by * the pos array. + * + * This method does not support glyph composition and decomposition and + * should therefore not be used to render complex scripts. * * @param text The text to be drawn * @param pos Array of [x,y] positions, used to position each character * @param paint The paint used for the text (e.g. color, size, style) */ + @Deprecated public void drawPosText(String text, float[] pos, Paint paint) { if (text.length()*2 > pos.length) { throw new ArrayIndexOutOfBoundsException(); @@ -1562,7 +1542,7 @@ public class Canvas { * @param paint The paint used for the text (e.g. color, size, style) */ public void drawTextOnPath(char[] text, int index, int count, Path path, - float hOffset, float vOffset, Paint paint) { + float hOffset, float vOffset, Paint paint) { if (index < 0 || index + count > text.length) { throw new ArrayIndexOutOfBoundsException(); } @@ -1584,12 +1564,10 @@ public class Canvas { * the text * @param paint The paint used for the text (e.g. color, size, style) */ - public void drawTextOnPath(String text, Path path, float hOffset, - float vOffset, Paint paint) { + public void drawTextOnPath(String text, Path path, float hOffset, float vOffset, Paint paint) { if (text.length() > 0) { - native_drawTextOnPath(mNativeCanvas, text, path.ni(), - hOffset, vOffset, paint.mBidiFlags, - paint.mNativePaint); + native_drawTextOnPath(mNativeCanvas, text, path.ni(), hOffset, vOffset, + paint.mBidiFlags, paint.mNativePaint); } } @@ -1612,8 +1590,7 @@ public class Canvas { save(); translate(dst.left, dst.top); if (picture.getWidth() > 0 && picture.getHeight() > 0) { - scale(dst.width() / picture.getWidth(), - dst.height() / picture.getHeight()); + scale(dst.width() / picture.getWidth(), dst.height() / picture.getHeight()); } drawPicture(picture); restore(); @@ -1626,8 +1603,8 @@ public class Canvas { save(); translate(dst.left, dst.top); if (picture.getWidth() > 0 && picture.getHeight() > 0) { - scale((float)dst.width() / picture.getWidth(), - (float)dst.height() / picture.getHeight()); + scale((float) dst.width() / picture.getWidth(), + (float) dst.height() / picture.getHeight()); } drawPicture(picture); restore(); diff --git a/graphics/java/android/graphics/DrawFilter.java b/graphics/java/android/graphics/DrawFilter.java index 6b44ed7..1f64539 100644 --- a/graphics/java/android/graphics/DrawFilter.java +++ b/graphics/java/android/graphics/DrawFilter.java @@ -28,7 +28,11 @@ public class DrawFilter { /* package */ int mNativeInt; // pointer to native object protected void finalize() throws Throwable { - nativeDestructor(mNativeInt); + try { + nativeDestructor(mNativeInt); + } finally { + super.finalize(); + } } private static native void nativeDestructor(int nativeDrawFilter); diff --git a/graphics/java/android/graphics/LinearGradient.java b/graphics/java/android/graphics/LinearGradient.java index 82ed199..96a71e3 100644 --- a/graphics/java/android/graphics/LinearGradient.java +++ b/graphics/java/android/graphics/LinearGradient.java @@ -28,8 +28,8 @@ public class LinearGradient extends Shader { the the colors are distributed evenly along the gradient line. @param tile The Shader tiling mode */ - public LinearGradient(float x0, float y0, float x1, float y1, - int colors[], float positions[], TileMode tile) { + public LinearGradient(float x0, float y0, float x1, float y1, int colors[], float positions[], + TileMode tile) { if (colors.length < 2) { throw new IllegalArgumentException("needs >= 2 number of colors"); } @@ -50,8 +50,8 @@ public class LinearGradient extends Shader { @param color1 The color at the end of the gradient line. @param tile The Shader tiling mode */ - public LinearGradient(float x0, float y0, float x1, float y1, - int color0, int color1, TileMode tile) { + public LinearGradient(float x0, float y0, float x1, float y1, int color0, int color1, + TileMode tile) { native_instance = nativeCreate2(x0, y0, x1, y1, color0, color1, tile.nativeInt); native_shader = nativePostCreate2(native_instance, x0, y0, x1, y1, color0, color1, tile.nativeInt); diff --git a/graphics/java/android/graphics/Paint.java b/graphics/java/android/graphics/Paint.java index ce42612..c97785e 100644 --- a/graphics/java/android/graphics/Paint.java +++ b/graphics/java/android/graphics/Paint.java @@ -528,6 +528,7 @@ public class Paint { * * @return true if the lineartext bit is set in the paint's flags */ + @Deprecated public final boolean isLinearText() { return (getFlags() & LINEAR_TEXT_FLAG) != 0; } @@ -538,6 +539,7 @@ public class Paint { * @param linearText true to set the linearText bit in the paint's flags, * false to clear it. */ + @Deprecated public native void setLinearText(boolean linearText); /** @@ -2142,8 +2144,6 @@ public class Paint { private static native void native_setTextAlign(int native_object, int align); - private static native float native_getFontMetrics(int native_paint, - FontMetrics metrics); private static native int native_getTextWidths(int native_object, char[] text, int index, int count, float[] widths); private static native int native_getTextWidths(int native_object, diff --git a/graphics/java/android/graphics/PaintFlagsDrawFilter.java b/graphics/java/android/graphics/PaintFlagsDrawFilter.java index 0f0d03d..c833a12 100644 --- a/graphics/java/android/graphics/PaintFlagsDrawFilter.java +++ b/graphics/java/android/graphics/PaintFlagsDrawFilter.java @@ -17,6 +17,10 @@ package android.graphics; public class PaintFlagsDrawFilter extends DrawFilter { + /** @hide **/ + public final int clearBits; + /** @hide **/ + public final int setBits; /** * Subclass of DrawFilter that affects every paint by first clearing @@ -27,6 +31,8 @@ public class PaintFlagsDrawFilter extends DrawFilter { * @param setBits These bits will be set in the paint's flags */ public PaintFlagsDrawFilter(int clearBits, int setBits) { + this.clearBits = clearBits; + this.setBits = setBits; // our native constructor can return 0, if the specified bits // are effectively a no-op mNativeInt = nativeConstructor(clearBits, setBits); diff --git a/graphics/java/android/graphics/PathMeasure.java b/graphics/java/android/graphics/PathMeasure.java index 98f7821..7062824 100644 --- a/graphics/java/android/graphics/PathMeasure.java +++ b/graphics/java/android/graphics/PathMeasure.java @@ -17,6 +17,7 @@ package android.graphics; public class PathMeasure { + private Path mPath; /** * Create an empty PathMeasure object. To uses this to measure the length @@ -28,6 +29,7 @@ public class PathMeasure { * is used. If the path is modified, you must call setPath with the path. */ public PathMeasure() { + mPath = null; native_instance = native_create(0, false); } @@ -46,8 +48,8 @@ public class PathMeasure { * even if its contour was not explicitly closed. */ public PathMeasure(Path path, boolean forceClosed) { - // note: the native side makes a copy of path, so we don't need a java - // reference to it here, since it's fine if it gets GC'd + // The native implementation does not copy the path, prevent it from being GC'd + mPath = path; native_instance = native_create(path != null ? path.ni() : 0, forceClosed); } @@ -56,8 +58,7 @@ public class PathMeasure { * Assign a new path, or null to have none. */ public void setPath(Path path, boolean forceClosed) { - // note: the native side makes a copy of path, so we don't need a java - // reference to it here, since it's fine if it gets GC'd + mPath = path; native_setPath(native_instance, path != null ? path.ni() : 0, forceClosed); diff --git a/graphics/java/android/graphics/Picture.java b/graphics/java/android/graphics/Picture.java index bbb2dbf..997141d 100644 --- a/graphics/java/android/graphics/Picture.java +++ b/graphics/java/android/graphics/Picture.java @@ -32,10 +32,15 @@ public class Picture { private Canvas mRecordingCanvas; private final int mNativePicture; + /** + * @hide + */ + public final boolean createdFromStream; + private static final int WORKING_STREAM_STORAGE = 16 * 1024; public Picture() { - this(nativeConstructor(0)); + this(nativeConstructor(0), false); } /** @@ -44,7 +49,7 @@ public class Picture { * changes will not be reflected in this picture. */ public Picture(Picture src) { - this(nativeConstructor(src != null ? src.mNativePicture : 0)); + this(nativeConstructor(src != null ? src.mNativePicture : 0), false); } /** @@ -101,15 +106,24 @@ public class Picture { /** * Create a new picture (already recorded) from the data in the stream. This * data was generated by a previous call to writeToStream(). + * + * <strong>Note:</strong> a picture created from an input stream cannot be + * replayed on a hardware accelerated canvas. + * + * @see #writeToStream(java.io.OutputStream) */ public static Picture createFromStream(InputStream stream) { - return new Picture( - nativeCreateFromStream(stream, new byte[WORKING_STREAM_STORAGE])); + return new Picture(nativeCreateFromStream(stream, new byte[WORKING_STREAM_STORAGE]), true); } /** * Write the picture contents to a stream. The data can be used to recreate * the picture in this or another process by calling createFromStream. + * + * <strong>Note:</strong> a picture created from an input stream cannot be + * replayed on a hardware accelerated canvas. + * + * @see #createFromStream(java.io.InputStream) */ public void writeToStream(OutputStream stream) { // do explicit check before calling the native method @@ -123,18 +137,23 @@ public class Picture { } protected void finalize() throws Throwable { - nativeDestructor(mNativePicture); + try { + nativeDestructor(mNativePicture); + } finally { + super.finalize(); + } } - - /*package*/ final int ni() { + + final int ni() { return mNativePicture; } - private Picture(int nativePicture) { + private Picture(int nativePicture, boolean fromStream) { if (nativePicture == 0) { throw new RuntimeException(); } mNativePicture = nativePicture; + createdFromStream = fromStream; } // return empty picture if src is 0, or a copy of the native src diff --git a/graphics/java/android/graphics/PixelFormat.java b/graphics/java/android/graphics/PixelFormat.java index 182f14d..f7c202f 100644 --- a/graphics/java/android/graphics/PixelFormat.java +++ b/graphics/java/android/graphics/PixelFormat.java @@ -39,11 +39,15 @@ public class PixelFormat public static final int RGB_888 = 3; public static final int RGB_565 = 4; + @Deprecated public static final int RGBA_5551 = 6; + @Deprecated public static final int RGBA_4444 = 7; public static final int A_8 = 8; public static final int L_8 = 9; + @Deprecated public static final int LA_88 = 0xA; + @Deprecated public static final int RGB_332 = 0xB; diff --git a/graphics/java/android/graphics/PixelXorXfermode.java b/graphics/java/android/graphics/PixelXorXfermode.java index 18d15cf..6075ec3 100644 --- a/graphics/java/android/graphics/PixelXorXfermode.java +++ b/graphics/java/android/graphics/PixelXorXfermode.java @@ -22,6 +22,7 @@ package android.graphics; * this mode *always* returns an opaque color (alpha == 255). Thus it is * not really usefull for operating on blended colors. */ +@Deprecated public class PixelXorXfermode extends Xfermode { public PixelXorXfermode(int opColor) { diff --git a/graphics/java/android/graphics/Rect.java b/graphics/java/android/graphics/Rect.java index 7830224..ec911b0 100644 --- a/graphics/java/android/graphics/Rect.java +++ b/graphics/java/android/graphics/Rect.java @@ -76,13 +76,21 @@ public final class Rect implements Parcelable { } @Override - public boolean equals(Object obj) { - Rect r = (Rect) obj; - if (r != null) { - return left == r.left && top == r.top && right == r.right - && bottom == r.bottom; - } - return false; + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Rect r = (Rect) o; + return left == r.left && top == r.top && right == r.right && bottom == r.bottom; + } + + @Override + public int hashCode() { + int result = left; + result = 31 * result + top; + result = 31 * result + right; + result = 31 * result + bottom; + return result; } @Override @@ -344,8 +352,7 @@ public final class Rect implements Parcelable { // check for empty first return this.left < this.right && this.top < this.bottom // now check for containment - && left <= r.left && top <= r.top - && right >= r.right && bottom >= r.bottom; + && left <= r.left && top <= r.top && right >= r.right && bottom >= r.bottom; } /** @@ -367,20 +374,11 @@ public final class Rect implements Parcelable { * return false and do not change this rectangle. */ public boolean intersect(int left, int top, int right, int bottom) { - if (this.left < right && left < this.right - && this.top < bottom && top < this.bottom) { - if (this.left < left) { - this.left = left; - } - if (this.top < top) { - this.top = top; - } - if (this.right > right) { - this.right = right; - } - if (this.bottom > bottom) { - this.bottom = bottom; - } + if (this.left < right && left < this.right && this.top < bottom && top < this.bottom) { + if (this.left < left) this.left = left; + if (this.top < top) this.top = top; + if (this.right > right) this.right = right; + if (this.bottom > bottom) this.bottom = bottom; return true; } return false; @@ -414,8 +412,7 @@ public final class Rect implements Parcelable { * false and do not change this rectangle. */ public boolean setIntersect(Rect a, Rect b) { - if (a.left < b.right && b.left < a.right - && a.top < b.bottom && b.top < a.bottom) { + if (a.left < b.right && b.left < a.right && a.top < b.bottom && b.top < a.bottom) { left = Math.max(a.left, b.left); top = Math.max(a.top, b.top); right = Math.min(a.right, b.right); @@ -440,8 +437,7 @@ public final class Rect implements Parcelable { * no event is this rectangle modified. */ public boolean intersects(int left, int top, int right, int bottom) { - return this.left < right && left < this.right - && this.top < bottom && top < this.bottom; + return this.left < right && left < this.right && this.top < bottom && top < this.bottom; } /** @@ -455,8 +451,7 @@ public final class Rect implements Parcelable { * either of the rectangles modified. */ public static boolean intersects(Rect a, Rect b) { - return a.left < b.right && b.left < a.right - && a.top < b.bottom && b.top < a.bottom; + return a.left < b.right && b.left < a.right && a.top < b.bottom && b.top < a.bottom; } /** @@ -472,14 +467,10 @@ public final class Rect implements Parcelable { public void union(int left, int top, int right, int bottom) { if ((left < right) && (top < bottom)) { if ((this.left < this.right) && (this.top < this.bottom)) { - if (this.left > left) - this.left = left; - if (this.top > top) - this.top = top; - if (this.right < right) - this.right = right; - if (this.bottom < bottom) - this.bottom = bottom; + if (this.left > left) this.left = left; + if (this.top > top) this.top = top; + if (this.right < right) this.right = right; + if (this.bottom < bottom) this.bottom = bottom; } else { this.left = left; this.top = top; diff --git a/graphics/java/android/graphics/RectF.java b/graphics/java/android/graphics/RectF.java index 00e9609..c633d84 100644 --- a/graphics/java/android/graphics/RectF.java +++ b/graphics/java/android/graphics/RectF.java @@ -79,6 +79,24 @@ public class RectF implements Parcelable { bottom = r.bottom; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + RectF r = (RectF) o; + return left == r.left && top == r.top && right == r.right && bottom == r.bottom; + } + + @Override + public int hashCode() { + int result = (left != +0.0f ? Float.floatToIntBits(left) : 0); + result = 31 * result + (top != +0.0f ? Float.floatToIntBits(top) : 0); + result = 31 * result + (right != +0.0f ? Float.floatToIntBits(right) : 0); + result = 31 * result + (bottom != +0.0f ? Float.floatToIntBits(bottom) : 0); + return result; + } + public String toString() { return "RectF(" + left + ", " + top + ", " + right + ", " + bottom + ")"; diff --git a/graphics/java/android/graphics/SurfaceTexture.java b/graphics/java/android/graphics/SurfaceTexture.java index 0521e69..e101581 100644 --- a/graphics/java/android/graphics/SurfaceTexture.java +++ b/graphics/java/android/graphics/SurfaceTexture.java @@ -161,7 +161,31 @@ public class SurfaceTexture { public void updateTexImage() { int err = nativeUpdateTexImage(); if (err != 0) { - throw new RuntimeException("Error during updateTexImage (see logs)"); + throw new RuntimeException("Error during updateTexImage (see logcat for details)"); + } + } + + /** + * Detach the SurfaceTexture from the OpenGL ES context with which it is currently associated. + * This can be used to change from one OpenGL ES context to another. + * + * @hide + */ + public void detachFromGLContext() { + int err = nativeDetachFromGLContext(); + if (err != 0) { + throw new RuntimeException("Error during detachFromGLContext (see logcat for details)"); + } + } + + /** + * + * @hide + */ + public void attachToGLContext(int texName) { + int err = nativeAttachToGLContext(texName); + if (err != 0) { + throw new RuntimeException("Error during detachFromGLContext (see logcat for details)"); } } @@ -269,6 +293,8 @@ public class SurfaceTexture { private native long nativeGetTimestamp(); private native void nativeSetDefaultBufferSize(int width, int height); private native int nativeUpdateTexImage(); + private native int nativeDetachFromGLContext(); + private native int nativeAttachToGLContext(int texName); private native int nativeGetQueuedCount(); private native void nativeRelease(); diff --git a/graphics/java/android/graphics/Typeface.java b/graphics/java/android/graphics/Typeface.java index ed6fa08..4487a3c 100644 --- a/graphics/java/android/graphics/Typeface.java +++ b/graphics/java/android/graphics/Typeface.java @@ -17,6 +17,7 @@ package android.graphics; import android.content.res.AssetManager; +import android.util.SparseArray; import java.io.File; @@ -43,9 +44,11 @@ public class Typeface { /** The NORMAL style of the default monospace typeface. */ public static final Typeface MONOSPACE; - /* package */ static Typeface[] sDefaults; - - /* package */ int native_instance; + static Typeface[] sDefaults; + private static final SparseArray<SparseArray<Typeface>> sTypefaceCache = + new SparseArray<SparseArray<Typeface>>(3); + + int native_instance; // Style public static final int NORMAL = 0; @@ -53,19 +56,21 @@ public class Typeface { public static final int ITALIC = 2; public static final int BOLD_ITALIC = 3; + private int mStyle = 0; + /** Returns the typeface's intrinsic style attributes */ public int getStyle() { - return nativeGetStyle(native_instance); + return mStyle; } /** Returns true if getStyle() has the BOLD bit set. */ public final boolean isBold() { - return (getStyle() & BOLD) != 0; + return (mStyle & BOLD) != 0; } /** Returns true if getStyle() has the ITALIC bit set. */ public final boolean isItalic() { - return (getStyle() & ITALIC) != 0; + return (mStyle & ITALIC) != 0; } /** @@ -97,9 +102,32 @@ public class Typeface { public static Typeface create(Typeface family, int style) { int ni = 0; if (family != null) { + // Return early if we're asked for the same face/style + if (family.mStyle == style) { + return family; + } + ni = family.native_instance; } - return new Typeface(nativeCreateFromTypeface(ni, style)); + + Typeface typeface; + SparseArray<Typeface> styles = sTypefaceCache.get(ni); + + if (styles != null) { + typeface = styles.get(style); + if (typeface != null) { + return typeface; + } + } + + typeface = new Typeface(nativeCreateFromTypeface(ni, style)); + if (styles == null) { + styles = new SparseArray<Typeface>(4); + sTypefaceCache.put(ni, styles); + } + styles.put(style, typeface); + + return typeface; } /** @@ -143,15 +171,17 @@ public class Typeface { // don't allow clients to call this directly private Typeface(int ni) { - if (0 == ni) { + if (ni == 0) { throw new RuntimeException("native typeface cannot be made"); } + native_instance = ni; + mStyle = nativeGetStyle(ni); } static { - DEFAULT = create((String)null, 0); - DEFAULT_BOLD = create((String)null, Typeface.BOLD); + DEFAULT = create((String) null, 0); + DEFAULT_BOLD = create((String) null, Typeface.BOLD); SANS_SERIF = create("sans-serif", 0); SERIF = create("serif", 0); MONOSPACE = create("monospace", 0); @@ -159,14 +189,34 @@ public class Typeface { sDefaults = new Typeface[] { DEFAULT, DEFAULT_BOLD, - create((String)null, Typeface.ITALIC), - create((String)null, Typeface.BOLD_ITALIC), + create((String) null, Typeface.ITALIC), + create((String) null, Typeface.BOLD_ITALIC), }; } protected void finalize() throws Throwable { - super.finalize(); - nativeUnref(native_instance); + try { + nativeUnref(native_instance); + } finally { + super.finalize(); + } + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Typeface typeface = (Typeface) o; + + return mStyle == typeface.mStyle && native_instance == typeface.native_instance; + } + + @Override + public int hashCode() { + int result = native_instance; + result = 31 * result + mStyle; + return result; } private static native int nativeCreate(String familyName, int style); diff --git a/graphics/java/android/graphics/drawable/AnimationDrawable.java b/graphics/java/android/graphics/drawable/AnimationDrawable.java index 35343be..7c7cd01 100644 --- a/graphics/java/android/graphics/drawable/AnimationDrawable.java +++ b/graphics/java/android/graphics/drawable/AnimationDrawable.java @@ -42,7 +42,7 @@ import android.util.AttributeSet; * <p>spin_animation.xml file in res/drawable/ folder:</p> * <pre><!-- Animation frames are wheel0.png -- wheel5.png files inside the * res/drawable/ folder --> - * <animation-list android:id="selected" android:oneshot="false"> + * <animation-list android:id="@+id/selected" android:oneshot="false"> * <item android:drawable="@drawable/wheel0" android:duration="50" /> * <item android:drawable="@drawable/wheel1" android:duration="50" /> * <item android:drawable="@drawable/wheel2" android:duration="50" /> @@ -226,6 +226,8 @@ public class AnimationDrawable extends DrawableContainer implements Runnable, An unscheduleSelf(this); } if (animate) { + // Unscheduling may have clobbered this value; restore it to record that we're animating + mCurFrame = frame; scheduleSelf(this, SystemClock.uptimeMillis() + mAnimationState.mDurations[frame]); } } diff --git a/graphics/java/android/graphics/drawable/ClipDrawable.java b/graphics/java/android/graphics/drawable/ClipDrawable.java index 29edc04..c41dd07 100644 --- a/graphics/java/android/graphics/drawable/ClipDrawable.java +++ b/graphics/java/android/graphics/drawable/ClipDrawable.java @@ -24,7 +24,6 @@ import android.content.res.TypedArray; import android.graphics.*; import android.view.Gravity; import android.util.AttributeSet; -import android.view.View; import java.io.IOException; diff --git a/graphics/java/android/graphics/drawable/Drawable.java b/graphics/java/android/graphics/drawable/Drawable.java index 4b9c98f..86e824b 100644 --- a/graphics/java/android/graphics/drawable/Drawable.java +++ b/graphics/java/android/graphics/drawable/Drawable.java @@ -296,8 +296,6 @@ public abstract class Drawable { /** * Implement this interface if you want to create an drawable that is RTL aware - * - * @hide */ public static interface Callback2 extends Callback { /** @@ -387,8 +385,6 @@ public abstract class Drawable { /** * Use the current {@link android.graphics.drawable.Drawable.Callback2} implementation to get * the resolved layout direction of this Drawable. - * - * @hide */ public int getResolvedLayoutDirectionSelf() { final Callback callback = getCallback(); @@ -777,7 +773,13 @@ public abstract class Drawable { np = null; pad = null; } - return drawableFromBitmap(res, bm, np, pad, srcName); + int[] layoutBounds = bm.getLayoutBounds(); + Rect layoutBoundsRect = null; + if (layoutBounds != null) { + layoutBoundsRect = new Rect(layoutBounds[0], layoutBounds[1], + layoutBounds[2], layoutBounds[3]); + } + return drawableFromBitmap(res, bm, np, pad, layoutBoundsRect, srcName); } return null; } @@ -879,7 +881,7 @@ public abstract class Drawable { Bitmap bm = BitmapFactory.decodeFile(pathName); if (bm != null) { - return drawableFromBitmap(null, bm, null, null, pathName); + return drawableFromBitmap(null, bm, null, null, null, pathName); } return null; @@ -960,10 +962,12 @@ public abstract class Drawable { } private static Drawable drawableFromBitmap(Resources res, Bitmap bm, byte[] np, - Rect pad, String srcName) { + Rect pad, Rect layoutBounds, String srcName) { if (np != null) { - return new NinePatchDrawable(res, bm, np, pad, srcName); + NinePatchDrawable npd = new NinePatchDrawable(res, bm, np, pad, srcName); + npd.setLayoutBounds(layoutBounds); + return npd; } return new BitmapDrawable(res, bm); diff --git a/graphics/java/android/graphics/drawable/GradientDrawable.java b/graphics/java/android/graphics/drawable/GradientDrawable.java index 50964d5..5b50beb 100644 --- a/graphics/java/android/graphics/drawable/GradientDrawable.java +++ b/graphics/java/android/graphics/drawable/GradientDrawable.java @@ -173,9 +173,20 @@ public class GradientDrawable extends Drawable { } /** - * Specify radii for each of the 4 corners. For each corner, the array - * contains 2 values, [X_radius, Y_radius]. The corners are ordered - * top-left, top-right, bottom-right, bottom-left + * <p>Specify radii for each of the 4 corners. For each corner, the array + * contains 2 values, <code>[X_radius, Y_radius]</code>. The corners are ordered + * top-left, top-right, bottom-right, bottom-left. This property + * is honored only when the shape is of type {@link #RECTANGLE}.</p> + * <p><strong>Note</strong>: changing this property will affect all instances + * of a drawable loaded from a resource. It is recommended to invoke + * {@link #mutate()} before changing this property.</p> + * + * @param radii 4 pairs of X and Y radius for each corner, specified in pixels. + * The length of this array must be >= 8 + * + * @see #mutate() + * @see #setCornerRadii(float[]) + * @see #setShape(int) */ public void setCornerRadii(float[] radii) { mGradientState.setCornerRadii(radii); @@ -184,23 +195,57 @@ public class GradientDrawable extends Drawable { } /** - * Specify radius for the corners of the gradient. If this is > 0, then the - * drawable is drawn in a round-rectangle, rather than a rectangle. + * <p>Specify radius for the corners of the gradient. If this is > 0, then the + * drawable is drawn in a round-rectangle, rather than a rectangle. This property + * is honored only when the shape is of type {@link #RECTANGLE}.</p> + * <p><strong>Note</strong>: changing this property will affect all instances + * of a drawable loaded from a resource. It is recommended to invoke + * {@link #mutate()} before changing this property.</p> + * + * @param radius The radius in pixels of the corners of the rectangle shape + * + * @see #mutate() + * @see #setCornerRadii(float[]) + * @see #setShape(int) */ public void setCornerRadius(float radius) { mGradientState.setCornerRadius(radius); mPathIsDirty = true; invalidateSelf(); } - + /** - * Set the stroke width and color for the drawable. If width is zero, - * then no stroke is drawn. + * <p>Set the stroke width and color for the drawable. If width is zero, + * then no stroke is drawn.</p> + * <p><strong>Note</strong>: changing this property will affect all instances + * of a drawable loaded from a resource. It is recommended to invoke + * {@link #mutate()} before changing this property.</p> + * + * @param width The width in pixels of the stroke + * @param color The color of the stroke + * + * @see #mutate() + * @see #setStroke(int, int, float, float) */ public void setStroke(int width, int color) { setStroke(width, color, 0, 0); } - + + /** + * <p>Set the stroke width and color for the drawable. If width is zero, + * then no stroke is drawn. This method can also be used to dash the stroke.</p> + * <p><strong>Note</strong>: changing this property will affect all instances + * of a drawable loaded from a resource. It is recommended to invoke + * {@link #mutate()} before changing this property.</p> + * + * @param width The width in pixels of the stroke + * @param color The color of the stroke + * @param dashWidth The length in pixels of the dashes, set to 0 to disable dashes + * @param dashGap The gap in pixels between dashes + * + * @see #mutate() + * @see #setStroke(int, int) + */ public void setStroke(int width, int color, float dashWidth, float dashGap) { mGradientState.setStroke(width, color, dashWidth, dashGap); @@ -218,13 +263,37 @@ public class GradientDrawable extends Drawable { mStrokePaint.setPathEffect(e); invalidateSelf(); } - + + + /** + * <p>Sets the size of the shape drawn by this drawable.</p> + * <p><strong>Note</strong>: changing this property will affect all instances + * of a drawable loaded from a resource. It is recommended to invoke + * {@link #mutate()} before changing this property.</p> + * + * @param width The width of the shape used by this drawable + * @param height The height of the shape used by this drawable + * + * @see #mutate() + * @see #setGradientType(int) + */ public void setSize(int width, int height) { mGradientState.setSize(width, height); mPathIsDirty = true; invalidateSelf(); } - + + /** + * <p>Sets the type of shape used to draw the gradient.</p> + * <p><strong>Note</strong>: changing this property will affect all instances + * of a drawable loaded from a resource. It is recommended to invoke + * {@link #mutate()} before changing this property.</p> + * + * @param shape The desired shape for this drawable: {@link #LINE}, + * {@link #OVAL}, {@link #RECTANGLE} or {@link #RING} + * + * @see #mutate() + */ public void setShape(int shape) { mRingPath = null; mPathIsDirty = true; @@ -232,24 +301,73 @@ public class GradientDrawable extends Drawable { invalidateSelf(); } + /** + * <p>Sets the type of gradient used by this drawable..</p> + * <p><strong>Note</strong>: changing this property will affect all instances + * of a drawable loaded from a resource. It is recommended to invoke + * {@link #mutate()} before changing this property.</p> + * + * @param gradient The type of the gradient: {@link #LINEAR_GRADIENT}, + * {@link #RADIAL_GRADIENT} or {@link #SWEEP_GRADIENT} + * + * @see #mutate() + */ public void setGradientType(int gradient) { mGradientState.setGradientType(gradient); mRectIsDirty = true; invalidateSelf(); } + /** + * <p>Sets the center location of the gradient. The radius is honored only when + * the gradient type is set to {@link #RADIAL_GRADIENT} or {@link #SWEEP_GRADIENT}.</p> + * <p><strong>Note</strong>: changing this property will affect all instances + * of a drawable loaded from a resource. It is recommended to invoke + * {@link #mutate()} before changing this property.</p> + * + * @param x The x coordinate of the gradient's center + * @param y The y coordinate of the gradient's center + * + * @see #mutate() + * @see #setGradientType(int) + */ public void setGradientCenter(float x, float y) { mGradientState.setGradientCenter(x, y); mRectIsDirty = true; invalidateSelf(); } + /** + * <p>Sets the radius of the gradient. The radius is honored only when the + * gradient type is set to {@link #RADIAL_GRADIENT}.</p> + * <p><strong>Note</strong>: changing this property will affect all instances + * of a drawable loaded from a resource. It is recommended to invoke + * {@link #mutate()} before changing this property.</p> + * + * @param gradientRadius The radius of the gradient in pixels + * + * @see #mutate() + * @see #setGradientType(int) + */ public void setGradientRadius(float gradientRadius) { mGradientState.setGradientRadius(gradientRadius); mRectIsDirty = true; invalidateSelf(); } + /** + * <p>Sets whether or not this drawable will honor its <code>level</code> + * property.</p> + * <p><strong>Note</strong>: changing this property will affect all instances + * of a drawable loaded from a resource. It is recommended to invoke + * {@link #mutate()} before changing this property.</p> + * + * @param useLevel True if this drawable should honor its level, false otherwise + * + * @see #mutate() + * @see #setLevel(int) + * @see #getLevel() + */ public void setUseLevel(boolean useLevel) { mGradientState.mUseLevel = useLevel; mRectIsDirty = true; @@ -261,6 +379,47 @@ public class GradientDrawable extends Drawable { return alpha * scale >> 8; } + /** + * Returns the orientation of the gradient defined in this drawable. + */ + public Orientation getOrientation() { + return mGradientState.mOrientation; + } + + /** + * <p>Changes the orientation of the gradient defined in this drawable.</p> + * <p><strong>Note</strong>: changing orientation will affect all instances + * of a drawable loaded from a resource. It is recommended to invoke + * {@link #mutate()} before changing the orientation.</p> + * + * @param orientation The desired orientation (angle) of the gradient + * + * @see #mutate() + */ + public void setOrientation(Orientation orientation) { + mGradientState.mOrientation = orientation; + mRectIsDirty = true; + invalidateSelf(); + } + + /** + * <p>Sets the colors used to draw the gradient. Each color is specified as an + * ARGB integer and the array must contain at least 2 colors.</p> + * <p><strong>Note</strong>: changing orientation will affect all instances + * of a drawable loaded from a resource. It is recommended to invoke + * {@link #mutate()} before changing the orientation.</p> + * + * @param colors 2 or more ARGB colors + * + * @see #mutate() + * @see #setColor(int) + */ + public void setColors(int[] colors) { + mGradientState.setColors(colors); + mRectIsDirty = true; + invalidateSelf(); + } + @Override public void draw(Canvas canvas) { if (!ensureValidRect()) { @@ -442,6 +601,17 @@ public class GradientDrawable extends Drawable { return ringPath; } + /** + * <p>Changes this drawbale to use a single color instead of a gradient.</p> + * <p><strong>Note</strong>: changing orientation will affect all instances + * of a drawable loaded from a resource. It is recommended to invoke + * {@link #mutate()} before changing the orientation.</p> + * + * @param argb The color used to fill the shape + * + * @see #mutate() + * @see #setColors(int[]) + */ public void setColor(int argb) { mGradientState.setSolidColor(argb); mFillPaint.setColor(argb); @@ -450,10 +620,9 @@ public class GradientDrawable extends Drawable { @Override public int getChangingConfigurations() { - return super.getChangingConfigurations() - | mGradientState.mChangingConfigurations; + return super.getChangingConfigurations() | mGradientState.mChangingConfigurations; } - + @Override public void setAlpha(int alpha) { if (alpha != mAlpha) { @@ -480,7 +649,6 @@ public class GradientDrawable extends Drawable { @Override public int getOpacity() { - // XXX need to figure out the actual opacity... return PixelFormat.TRANSLUCENT; } @@ -911,11 +1079,6 @@ public class GradientDrawable extends Drawable { private float mGradientRadius = 0.5f; private boolean mUseLevel; private boolean mUseLevelForShape; - - - GradientState() { - mOrientation = Orientation.TOP_BOTTOM; - } GradientState(Orientation orientation, int[] colors) { mOrientation = orientation; @@ -987,6 +1150,11 @@ public class GradientDrawable extends Drawable { mCenterY = y; } + public void setColors(int[] colors) { + mHasSolidColor = false; + mColors = colors; + } + public void setSolidColor(int argb) { mHasSolidColor = true; mSolidColor = argb; @@ -1055,4 +1223,3 @@ public class GradientDrawable extends Drawable { } } } - diff --git a/graphics/java/android/graphics/drawable/LayerDrawable.java b/graphics/java/android/graphics/drawable/LayerDrawable.java index 6698d31..383fe71 100644 --- a/graphics/java/android/graphics/drawable/LayerDrawable.java +++ b/graphics/java/android/graphics/drawable/LayerDrawable.java @@ -575,6 +575,11 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { @Override public Drawable mutate() { if (!mMutated && super.mutate() == this) { + if (!mLayerState.canConstantState()) { + throw new IllegalStateException("One or more children of this LayerDrawable does " + + "not have constant state; this drawable cannot be mutated."); + } + mLayerState = new LayerState(mLayerState, this, null); final ChildDrawable[] array = mLayerState.mChildren; final int N = mLayerState.mNum; for (int i = 0; i < N; i++) { @@ -694,7 +699,7 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { return stateful; } - public synchronized boolean canConstantState() { + public boolean canConstantState() { if (!mCheckedConstantState && mChildren != null) { mCanConstantState = true; final int N = mNum; diff --git a/graphics/java/android/graphics/drawable/NinePatchDrawable.java b/graphics/java/android/graphics/drawable/NinePatchDrawable.java index 18b8bc7..1272071 100644 --- a/graphics/java/android/graphics/drawable/NinePatchDrawable.java +++ b/graphics/java/android/graphics/drawable/NinePatchDrawable.java @@ -47,6 +47,7 @@ public class NinePatchDrawable extends Drawable { private NinePatchState mNinePatchState; private NinePatch mNinePatch; private Rect mPadding; + private Rect mLayoutBounds; private Paint mPaint; private boolean mMutated; @@ -98,6 +99,13 @@ public class NinePatchDrawable extends Drawable { mNinePatchState.mTargetDensity = mTargetDensity; } + /** + * @hide + */ + void setLayoutBounds(Rect layoutBounds) { + mLayoutBounds = layoutBounds; + } + private void setNinePatchState(NinePatchState state, Resources res) { mNinePatchState = state; mNinePatch = state.mNinePatch; @@ -258,7 +266,7 @@ public class NinePatchDrawable extends Drawable { } options.inScreenDensity = DisplayMetrics.DENSITY_DEVICE; - final Rect padding = new Rect(); + final Rect padding = new Rect(); Bitmap bitmap = null; try { diff --git a/graphics/java/android/graphics/drawable/ScaleDrawable.java b/graphics/java/android/graphics/drawable/ScaleDrawable.java index 5fd5a16..ccad250 100644 --- a/graphics/java/android/graphics/drawable/ScaleDrawable.java +++ b/graphics/java/android/graphics/drawable/ScaleDrawable.java @@ -24,7 +24,6 @@ import android.content.res.TypedArray; import android.graphics.*; import android.view.Gravity; import android.util.AttributeSet; -import android.view.View; import java.io.IOException; diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java index f285f5b..cd5300d 100644 --- a/graphics/java/android/renderscript/Allocation.java +++ b/graphics/java/android/renderscript/Allocation.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 The Android Open Source Project + * Copyright (C) 2008-2012 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. @@ -22,6 +22,8 @@ import android.content.res.Resources; import android.content.res.AssetManager; import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import android.view.Surface; +import android.graphics.SurfaceTexture; import android.util.Log; import android.util.TypedValue; @@ -78,6 +80,8 @@ public class Allocation extends BaseObj { boolean mConstrainedFace; boolean mConstrainedY; boolean mConstrainedZ; + boolean mReadAllowed = true; + boolean mWriteAllowed = true; int mSelectedY; int mSelectedZ; int mSelectedLOD; @@ -99,7 +103,7 @@ public class Allocation extends BaseObj { public static final int USAGE_SCRIPT = 0x0001; /** - * GRAPHICS_TEXTURE The allcation will be used as a texture + * GRAPHICS_TEXTURE The allocation will be used as a texture * source by one or more graphics programs. * */ @@ -121,12 +125,29 @@ public class Allocation extends BaseObj { public static final int USAGE_GRAPHICS_CONSTANTS = 0x0008; /** - * USAGE_GRAPHICS_RENDER_TARGET The allcation will be used as a + * USAGE_GRAPHICS_RENDER_TARGET The allocation will be used as a * target for offscreen rendering * */ public static final int USAGE_GRAPHICS_RENDER_TARGET = 0x0010; + /** + * USAGE_IO_INPUT The allocation will be used as SurfaceTexture + * consumer. This usage will cause the allocation to be created + * read only. + * + * @hide + */ + public static final int USAGE_IO_INPUT = 0x0020; + + /** + * USAGE_IO_OUTPUT The allocation will be used as a + * SurfaceTexture producer. The dimensions and format of the + * SurfaceTexture will be forced to those of the allocation. + * + * @hide + */ + public static final int USAGE_IO_OUTPUT = 0x0040; /** * Controls mipmap behavior when using the bitmap creation and @@ -163,9 +184,43 @@ public class Allocation extends BaseObj { private int getIDSafe() { if (mAdaptedAllocation != null) { - return mAdaptedAllocation.getID(); + return mAdaptedAllocation.getID(mRS); } - return getID(); + return getID(mRS); + } + + + /** + * Get the element of the type of the Allocation. + * + * @hide + * @return Element + * + */ + public Element getElement() { + return mType.getElement(); + } + + /** + * Get the usage flags of the Allocation. + * + * @hide + * @return usage + * + */ + public int getUsage() { + return mUsage; + } + + /** + * Get the size of the Allocation in bytes. + * + * @hide + * @return sizeInBytes + * + */ + public int getSizeBytes() { + return mType.getCount() * mType.getElement().getSizeBytes(); } private void updateCacheInfo(Type t) { @@ -187,10 +242,24 @@ public class Allocation extends BaseObj { USAGE_GRAPHICS_TEXTURE | USAGE_GRAPHICS_VERTEX | USAGE_GRAPHICS_CONSTANTS | - USAGE_GRAPHICS_RENDER_TARGET)) != 0) { + USAGE_GRAPHICS_RENDER_TARGET | + USAGE_IO_INPUT | + USAGE_IO_OUTPUT)) != 0) { throw new RSIllegalArgumentException("Unknown usage specified."); } + + if ((usage & USAGE_IO_INPUT) != 0) { + mWriteAllowed = false; + + if ((usage & ~(USAGE_IO_INPUT | + USAGE_GRAPHICS_TEXTURE | + USAGE_SCRIPT)) != 0) { + throw new RSIllegalArgumentException("Invalid usage combination."); + } + } + mType = t; + mUsage = usage; if (t != null) { updateCacheInfo(t); @@ -252,7 +321,7 @@ public class Allocation extends BaseObj { @Override void updateFromNative() { super.updateFromNative(); - int typeID = mRS.nAllocationGetType(getID()); + int typeID = mRS.nAllocationGetType(getID(mRS)); if(typeID != 0) { mType = new Type(typeID, mRS); mType.updateFromNative(); @@ -260,10 +329,21 @@ public class Allocation extends BaseObj { } } + /** + * Get the type of the Allocation. + * + * @return Type + * + */ public Type getType() { return mType; } + /** + * Propagate changes from one usage of the allocation to the + * remaining usages of the allocation. + * + */ public void syncAll(int srcLocation) { switch (srcLocation) { case USAGE_SCRIPT: @@ -278,6 +358,50 @@ public class Allocation extends BaseObj { mRS.nAllocationSyncAll(getIDSafe(), srcLocation); } + /** + * Send a buffer to the output stream. The contents of the + * Allocation will be undefined after this operation. + * + * @hide + * + */ + public void ioSend() { + if ((mUsage & USAGE_IO_OUTPUT) == 0) { + throw new RSIllegalArgumentException( + "Can only send buffer if IO_OUTPUT usage specified."); + } + mRS.validate(); + mRS.nAllocationIoSend(getID(mRS)); + } + + /** + * Delete once code is updated. + * @hide + */ + public void ioSendOutput() { + ioSend(); + } + + /** + * Receive the latest input into the Allocation. + * + * @hide + * + */ + public void ioReceive() { + if ((mUsage & USAGE_IO_INPUT) == 0) { + throw new RSIllegalArgumentException( + "Can only receive if IO_INPUT usage specified."); + } + mRS.validate(); + mRS.nAllocationIoReceive(getID(mRS)); + } + + /** + * Copy an array of RS objects to the allocation. + * + * @param d Source array. + */ public void copyFrom(BaseObj[] d) { mRS.validate(); validateIsObject(); @@ -287,7 +411,7 @@ public class Allocation extends BaseObj { } int i[] = new int[d.length]; for (int ct=0; ct < d.length; ct++) { - i[ct] = d[ct].getID(); + i[ct] = d[ct].getID(mRS); } copy1DRangeFromUnchecked(0, mCurrentCount, i); } @@ -447,7 +571,7 @@ public class Allocation extends BaseObj { mRS.validate(); validateBitmapSize(b); validateBitmapFormat(b); - mRS.nAllocationCopyFromBitmap(getID(), b); + mRS.nAllocationCopyFromBitmap(getID(mRS), b); } /** @@ -458,6 +582,7 @@ public class Allocation extends BaseObj { * @param fp */ public void setFromFieldPacker(int xoff, FieldPacker fp) { + mRS.validate(); int eSize = mType.mElement.getSizeBytes(); final byte[] data = fp.getData(); @@ -478,6 +603,7 @@ public class Allocation extends BaseObj { * @param fp */ public void setFromFieldPacker(int xoff, int component_number, FieldPacker fp) { + mRS.validate(); if (component_number >= mType.mElement.mElements.length) { throw new RSIllegalArgumentException("Component_number " + component_number + " out of range."); } @@ -487,6 +613,7 @@ public class Allocation extends BaseObj { final byte[] data = fp.getData(); int eSize = mType.mElement.mElements[component_number].getSizeBytes(); + eSize *= mType.mElement.mArraySizes[component_number]; if (data.length != eSize) { throw new RSIllegalArgumentException("Field packer sizelength " + data.length + @@ -525,7 +652,7 @@ public class Allocation extends BaseObj { * followup sync will be required. */ public void generateMipmaps() { - mRS.nAllocationGenerateMipmaps(getID()); + mRS.nAllocationGenerateMipmaps(getID(mRS)); } /** @@ -653,7 +780,7 @@ public class Allocation extends BaseObj { public void copy1DRangeFrom(int off, int count, Allocation data, int dataOff) { mRS.nAllocationData2D(getIDSafe(), off, 0, mSelectedLOD, mSelectedFace.mID, - count, 1, data.getID(), dataOff, 0, + count, 1, data.getID(mRS), dataOff, 0, data.mSelectedLOD, data.mSelectedFace.mID); } @@ -730,7 +857,7 @@ public class Allocation extends BaseObj { validate2DRange(xoff, yoff, w, h); mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, - w, h, data.getID(), dataXoff, dataYoff, + w, h, data.getID(mRS), dataXoff, dataYoff, data.mSelectedLOD, data.mSelectedFace.mID); } @@ -761,7 +888,7 @@ public class Allocation extends BaseObj { mRS.validate(); validateBitmapFormat(b); validateBitmapSize(b); - mRS.nAllocationCopyToBitmap(getID(), b); + mRS.nAllocationCopyToBitmap(getID(mRS), b); } /** @@ -774,7 +901,7 @@ public class Allocation extends BaseObj { public void copyTo(byte[] d) { validateIsInt8(); mRS.validate(); - mRS.nAllocationRead(getID(), d); + mRS.nAllocationRead(getID(mRS), d); } /** @@ -787,7 +914,7 @@ public class Allocation extends BaseObj { public void copyTo(short[] d) { validateIsInt16(); mRS.validate(); - mRS.nAllocationRead(getID(), d); + mRS.nAllocationRead(getID(mRS), d); } /** @@ -800,7 +927,7 @@ public class Allocation extends BaseObj { public void copyTo(int[] d) { validateIsInt32(); mRS.validate(); - mRS.nAllocationRead(getID(), d); + mRS.nAllocationRead(getID(mRS), d); } /** @@ -813,7 +940,7 @@ public class Allocation extends BaseObj { public void copyTo(float[] d) { validateIsFloat32(); mRS.validate(); - mRS.nAllocationRead(getID(), d); + mRS.nAllocationRead(getID(mRS), d); } /** @@ -832,26 +959,46 @@ public class Allocation extends BaseObj { if ((mType.getY() > 0)|| (mType.getZ() > 0) || mType.hasFaces() || mType.hasMipmaps()) { throw new RSInvalidStateException("Resize only support for 1D allocations at this time."); } - mRS.nAllocationResize1D(getID(), dimX); + mRS.nAllocationResize1D(getID(mRS), dimX); mRS.finish(); // Necessary because resize is fifoed and update is async. - int typeID = mRS.nAllocationGetType(getID()); + int typeID = mRS.nAllocationGetType(getID(mRS)); mType = new Type(typeID, mRS); mType.updateFromNative(); updateCacheInfo(mType); } - /* + /** + * Resize a 2D allocation. The contents of the allocation are + * preserved. If new elements are allocated objects are created + * with null contents and the new region is otherwise undefined. + * + * If the new region is smaller the references of any objects + * outside the new region will be released. + * + * A new type will be created with the new dimension. + * + * @hide + * @param dimX The new size of the allocation. + * @param dimY The new size of the allocation. + */ public void resize(int dimX, int dimY) { - if ((mType.getZ() > 0) || mType.getFaces() || mType.getLOD()) { - throw new RSIllegalStateException("Resize only support for 2D allocations at this time."); + if ((mType.getZ() > 0) || mType.hasFaces() || mType.hasMipmaps()) { + throw new RSInvalidStateException( + "Resize only support for 2D allocations at this time."); } if (mType.getY() == 0) { - throw new RSIllegalStateException("Resize only support for 2D allocations at this time."); + throw new RSInvalidStateException( + "Resize only support for 2D allocations at this time."); } - mRS.nAllocationResize2D(getID(), dimX, dimY); + mRS.nAllocationResize2D(getID(mRS), dimX, dimY); + mRS.finish(); // Necessary because resize is fifoed and update is async. + + int typeID = mRS.nAllocationGetType(getID(mRS)); + mType = new Type(typeID, mRS); + mType.updateFromNative(); + updateCacheInfo(mType); } - */ @@ -872,10 +1019,34 @@ public class Allocation extends BaseObj { */ static public Allocation createTyped(RenderScript rs, Type type, MipmapControl mips, int usage) { rs.validate(); - if (type.getID() == 0) { + if (type.getID(rs) == 0) { + throw new RSInvalidStateException("Bad Type"); + } + int id = rs.nAllocationCreateTyped(type.getID(rs), mips.mID, usage, 0); + if (id == 0) { + throw new RSRuntimeException("Allocation creation failed."); + } + return new Allocation(id, rs, type, usage); + } + + /** + * @hide + * This API is hidden and only intended to be used for + * transitional purposes. + * + * @param type renderscript type describing data layout + * @param mips specifies desired mipmap behaviour for the + * allocation + * @param usage bit field specifying how the allocation is + * utilized + */ + static public Allocation createTyped(RenderScript rs, Type type, MipmapControl mips, + int usage, int pointer) { + rs.validate(); + if (type.getID(rs) == 0) { throw new RSInvalidStateException("Bad Type"); } - int id = rs.nAllocationCreateTyped(type.getID(), mips.mID, usage); + int id = rs.nAllocationCreateTyped(type.getID(rs), mips.mID, usage, pointer); if (id == 0) { throw new RSRuntimeException("Allocation creation failed."); } @@ -930,7 +1101,7 @@ public class Allocation extends BaseObj { b.setX(count); Type t = b.create(); - int id = rs.nAllocationCreateTyped(t.getID(), MipmapControl.MIPMAP_NONE.mID, usage); + int id = rs.nAllocationCreateTyped(t.getID(rs), MipmapControl.MIPMAP_NONE.mID, usage, 0); if (id == 0) { throw new RSRuntimeException("Allocation creation failed."); } @@ -997,7 +1168,7 @@ public class Allocation extends BaseObj { rs.validate(); Type t = typeFromBitmap(rs, b, mips); - int id = rs.nAllocationCreateFromBitmap(t.getID(), mips.mID, b, usage); + int id = rs.nAllocationCreateFromBitmap(t.getID(rs), mips.mID, b, usage); if (id == 0) { throw new RSRuntimeException("Load failed."); } @@ -1005,6 +1176,58 @@ public class Allocation extends BaseObj { } /** + * + * + * @hide + * + */ + public SurfaceTexture getSurfaceTexture() { + if ((mUsage & USAGE_IO_INPUT) == 0) { + throw new RSInvalidStateException("Allocation is not a surface texture."); + } + + int id = mRS.nAllocationGetSurfaceTextureID(getID(mRS)); + SurfaceTexture st = new SurfaceTexture(id); + mRS.nAllocationGetSurfaceTextureID2(getID(mRS), st); + + return st; + } + + /** + * + * @hide + * + */ + public Surface getSurface() { + return new Surface(getSurfaceTexture()); + } + + /** + * @hide + */ + public void setSurface(Surface sur) { + mRS.validate(); + if ((mUsage & USAGE_IO_OUTPUT) == 0) { + throw new RSInvalidStateException("Allocation is not USAGE_IO_OUTPUT."); + } + + mRS.nAllocationSetSurface(getID(mRS), sur); + } + + /** + * @hide + */ + public void setSurfaceTexture(SurfaceTexture st) { + mRS.validate(); + if ((mUsage & USAGE_IO_OUTPUT) == 0) { + throw new RSInvalidStateException("Allocation is not USAGE_IO_OUTPUT."); + } + + Surface s = new Surface(st); + mRS.nAllocationSetSurface(getID(mRS), s); + } + + /** * Creates a non-mipmapped renderscript allocation to use as a * graphics texture * @@ -1060,7 +1283,7 @@ public class Allocation extends BaseObj { tb.setMipmaps(mips == MipmapControl.MIPMAP_FULL); Type t = tb.create(); - int id = rs.nAllocationCubeCreateFromBitmap(t.getID(), mips.mID, b, usage); + int id = rs.nAllocationCubeCreateFromBitmap(t.getID(rs), mips.mID, b, usage); if(id == 0) { throw new RSRuntimeException("Load failed for bitmap " + b + " element " + e); } diff --git a/graphics/java/android/renderscript/AllocationAdapter.java b/graphics/java/android/renderscript/AllocationAdapter.java index d38f2df..85d86e5 100644 --- a/graphics/java/android/renderscript/AllocationAdapter.java +++ b/graphics/java/android/renderscript/AllocationAdapter.java @@ -30,7 +30,7 @@ public class AllocationAdapter extends Allocation { mAdaptedAllocation = alloc; } - int getID() { + int getID(RenderScript rs) { throw new RSInvalidStateException( "This operation is not supported with adapters at this time."); } diff --git a/graphics/java/android/renderscript/BaseObj.java b/graphics/java/android/renderscript/BaseObj.java index 2e55c48..f464f9b 100644 --- a/graphics/java/android/renderscript/BaseObj.java +++ b/graphics/java/android/renderscript/BaseObj.java @@ -43,16 +43,22 @@ public class BaseObj { * Lookup the native object ID for this object. Primarily used by the * generated reflected code. * + * @param rs Context to verify against internal context for + * match. * * @return int */ - int getID() { + int getID(RenderScript rs) { + mRS.validate(); if (mDestroyed) { throw new RSInvalidStateException("using a destroyed object."); } if (mID == 0) { throw new RSRuntimeException("Internal error: Object id 0."); } + if ((rs != null) && (rs != mRS)) { + throw new RSInvalidStateException("using object with mismatched context."); + } return mID; } @@ -138,7 +144,7 @@ public class BaseObj { */ void updateFromNative() { mRS.validate(); - mName = mRS.nGetName(getID()); + mName = mRS.nGetName(getID(mRS)); } /** diff --git a/graphics/java/android/renderscript/Element.java b/graphics/java/android/renderscript/Element.java index d378a78..d75c951 100644 --- a/graphics/java/android/renderscript/Element.java +++ b/graphics/java/android/renderscript/Element.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 The Android Open Source Project + * Copyright (C) 2008-2012 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. @@ -54,26 +54,59 @@ public class Element extends BaseObj { int[] mArraySizes; int[] mOffsetInBytes; + int[] mVisibleElementMap; + DataType mType; DataKind mKind; boolean mNormalized; int mVectorSize; + private void updateVisibleSubElements() { + if (mElements == null) { + return; + } + + int noPaddingFieldCount = 0; + int fieldCount = mElementNames.length; + // Find out how many elements are not padding + for (int ct = 0; ct < fieldCount; ct ++) { + if (mElementNames[ct].charAt(0) != '#') { + noPaddingFieldCount ++; + } + } + mVisibleElementMap = new int[noPaddingFieldCount]; + + // Make a map that points us at non-padding elements + for (int ct = 0, ctNoPadding = 0; ct < fieldCount; ct ++) { + if (mElementNames[ct].charAt(0) != '#') { + mVisibleElementMap[ctNoPadding ++] = ct; + } + } + } + /** * @hide * @return element size in bytes */ public int getSizeBytes() {return mSize;} + /** + * @hide + * @return element vector size + */ + public int getVectorSize() {return mVectorSize;} + /** * DataType represents the basic type information for a basic element. The - * naming convention follows. For numeric types its FLOAT, SIGNED, UNSIGNED - * followed by the _BITS where BITS is the size of the data. BOOLEAN is a - * true / false (1,0) represented in an 8 bit container. The UNSIGNED - * variants with multiple bit definitions are for packed graphical data - * formats and represents vectors with per vector member sizes which are - * treated as a single unit for packing and alignment purposes. + * naming convention follows. For numeric types it is FLOAT, + * SIGNED, or UNSIGNED followed by the _BITS where BITS is the + * size of the data. BOOLEAN is a true / false (1,0) + * represented in an 8 bit container. The UNSIGNED variants + * with multiple bit definitions are for packed graphical data + * formats and represent vectors with per vector member sizes + * which are treated as a single unit for packing and alignment + * purposes. * * MATRIX the three matrix types contain FLOAT_32 elements and are treated * as 32 bits for alignment purposes. @@ -81,6 +114,11 @@ public class Element extends BaseObj { * RS_* objects. 32 bit opaque handles. */ public enum DataType { + /** + * @hide + * new enum + */ + NONE (0, 0), //FLOAT_16 (1, 2), FLOAT_32 (2, 4), FLOAT_64 (3, 8), @@ -167,10 +205,10 @@ public class Element extends BaseObj { * @return number of sub-elements in this element */ public int getSubElementCount() { - if (mElements == null) { + if (mVisibleElementMap == null) { return 0; } - return mElements.length; + return mVisibleElementMap.length; } /** @@ -179,13 +217,13 @@ public class Element extends BaseObj { * @return sub-element in this element at given index */ public Element getSubElement(int index) { - if (mElements == null) { + if (mVisibleElementMap == null) { throw new RSIllegalArgumentException("Element contains no sub-elements"); } - if (index < 0 || index >= mElements.length) { + if (index < 0 || index >= mVisibleElementMap.length) { throw new RSIllegalArgumentException("Illegal sub-element index"); } - return mElements[index]; + return mElements[mVisibleElementMap[index]]; } /** @@ -194,13 +232,13 @@ public class Element extends BaseObj { * @return sub-element in this element at given index */ public String getSubElementName(int index) { - if (mElements == null) { + if (mVisibleElementMap == null) { throw new RSIllegalArgumentException("Element contains no sub-elements"); } - if (index < 0 || index >= mElements.length) { + if (index < 0 || index >= mVisibleElementMap.length) { throw new RSIllegalArgumentException("Illegal sub-element index"); } - return mElementNames[index]; + return mElementNames[mVisibleElementMap[index]]; } /** @@ -209,13 +247,13 @@ public class Element extends BaseObj { * @return array size of sub-element in this element at given index */ public int getSubElementArraySize(int index) { - if (mElements == null) { + if (mVisibleElementMap == null) { throw new RSIllegalArgumentException("Element contains no sub-elements"); } - if (index < 0 || index >= mElements.length) { + if (index < 0 || index >= mVisibleElementMap.length) { throw new RSIllegalArgumentException("Illegal sub-element index"); } - return mArraySizes[index]; + return mArraySizes[mVisibleElementMap[index]]; } /** @@ -224,13 +262,29 @@ public class Element extends BaseObj { * @return offset in bytes of sub-element in this element at given index */ public int getSubElementOffsetBytes(int index) { - if (mElements == null) { + if (mVisibleElementMap == null) { throw new RSIllegalArgumentException("Element contains no sub-elements"); } - if (index < 0 || index >= mElements.length) { + if (index < 0 || index >= mVisibleElementMap.length) { throw new RSIllegalArgumentException("Illegal sub-element index"); } - return mOffsetInBytes[index]; + return mOffsetInBytes[mVisibleElementMap[index]]; + } + + /** + * @hide + * @return element data type + */ + public DataType getDataType() { + return mType; + } + + /** + * @hide + * @return element data kind + */ + public DataKind getDataKind() { + return mKind; } /** @@ -681,14 +735,18 @@ public class Element extends BaseObj { Element(int id, RenderScript rs, Element[] e, String[] n, int[] as) { super(id, rs); mSize = 0; + mVectorSize = 1; mElements = e; mElementNames = n; mArraySizes = as; + mType = DataType.NONE; + mKind = DataKind.USER; mOffsetInBytes = new int[mElements.length]; for (int ct = 0; ct < mElements.length; ct++ ) { mOffsetInBytes[ct] = mSize; mSize += mElements[ct].mSize * mArraySizes[ct]; } + updateVisibleSubElements(); } Element(int id, RenderScript rs, DataType dt, DataKind dk, boolean norm, int size) { @@ -696,7 +754,11 @@ public class Element extends BaseObj { if ((dt != DataType.UNSIGNED_5_6_5) && (dt != DataType.UNSIGNED_4_4_4_4) && (dt != DataType.UNSIGNED_5_5_5_1)) { - mSize = dt.mSize * size; + if (size == 3) { + mSize = dt.mSize * 4; + } else { + mSize = dt.mSize * size; + } } else { mSize = dt.mSize; } @@ -716,7 +778,7 @@ public class Element extends BaseObj { // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements int[] dataBuffer = new int[5]; - mRS.nElementGetNativeData(getID(), dataBuffer); + mRS.nElementGetNativeData(getID(mRS), dataBuffer); mNormalized = dataBuffer[2] == 1 ? true : false; mVectorSize = dataBuffer[3]; @@ -741,7 +803,7 @@ public class Element extends BaseObj { mOffsetInBytes = new int[numSubElements]; int[] subElementIds = new int[numSubElements]; - mRS.nElementGetSubElements(getID(), subElementIds, mElementNames, mArraySizes); + mRS.nElementGetSubElements(getID(mRS), subElementIds, mElementNames, mArraySizes); for(int i = 0; i < numSubElements; i ++) { mElements[i] = new Element(subElementIds[i], mRS); mElements[i].updateFromNative(); @@ -749,7 +811,7 @@ public class Element extends BaseObj { mSize += mElements[i].mSize * mArraySizes[i]; } } - + updateVisibleSubElements(); } /** @@ -770,10 +832,12 @@ public class Element extends BaseObj { /** * Create a custom vector element of the specified DataType and vector size. - * DataKind will be set to USER. + * DataKind will be set to USER. Only primitive types (FLOAT_32, FLOAT_64, + * SIGNED_8, SIGNED_16, SIGNED_32, SIGNED_64, UNSIGNED_8, UNSIGNED_16, + * UNSIGNED_32, UNSIGNED_64, BOOLEAN) are supported. * * @param rs The context associated with the new Element. - * @param dt The DataType for the new element. + * @param dt The DataType for the new Element. * @param size Vector size for the new Element. Range 2-4 inclusive * supported. * @@ -783,10 +847,31 @@ public class Element extends BaseObj { if (size < 2 || size > 4) { throw new RSIllegalArgumentException("Vector size out of range 2-4."); } - DataKind dk = DataKind.USER; - boolean norm = false; - int id = rs.nElementCreate(dt.mID, dk.mID, norm, size); - return new Element(id, rs, dt, dk, norm, size); + + switch (dt) { + // Support only primitive integer/float/boolean types as vectors. + case FLOAT_32: + case FLOAT_64: + case SIGNED_8: + case SIGNED_16: + case SIGNED_32: + case SIGNED_64: + case UNSIGNED_8: + case UNSIGNED_16: + case UNSIGNED_32: + case UNSIGNED_64: + case BOOLEAN: { + DataKind dk = DataKind.USER; + boolean norm = false; + int id = rs.nElementCreate(dt.mID, dk.mID, norm, size); + return new Element(id, rs, dt, dk, norm, size); + } + + default: { + throw new RSIllegalArgumentException("Cannot create vector of " + + "non-primitive type."); + } + } } /** @@ -871,10 +956,10 @@ public class Element extends BaseObj { // Ignore mKind because it is allowed to be different (user vs. pixel). // We also ignore mNormalized because it can be different. The mType - // field must be non-null since we require name equivalence for - // user-created Elements. + // field must not be NONE since we require name equivalence for + // all user-created Elements. return ((mSize == e.mSize) && - (mType != null) && + (mType != DataType.NONE) && (mType == e.mType) && (mVectorSize == e.mVectorSize)); } @@ -891,6 +976,7 @@ public class Element extends BaseObj { String[] mElementNames; int[] mArraySizes; int mCount; + int mSkipPadding; /** * Create a builder object. @@ -916,6 +1002,21 @@ public class Element extends BaseObj { if (arraySize < 1) { throw new RSIllegalArgumentException("Array size cannot be less than 1."); } + + // Skip padding fields after a vector 3 type. + if (mSkipPadding != 0) { + if (name.startsWith("#padding_")) { + mSkipPadding = 0; + return this; + } + } + + if (element.mVectorSize == 3) { + mSkipPadding = 1; + } else { + mSkipPadding = 0; + } + if(mCount == mElements.length) { Element[] e = new Element[mCount + 8]; String[] s = new String[mCount + 8]; @@ -961,7 +1062,7 @@ public class Element extends BaseObj { int[] ids = new int[ein.length]; for (int ct = 0; ct < ein.length; ct++ ) { - ids[ct] = ein[ct].getID(); + ids[ct] = ein[ct].getID(mRS); } int id = mRS.nElementCreate2(ids, sin, asin); return new Element(id, mRS, ein, sin, asin); diff --git a/graphics/java/android/renderscript/FieldPacker.java b/graphics/java/android/renderscript/FieldPacker.java index 2739a4b8..a215a57 100644 --- a/graphics/java/android/renderscript/FieldPacker.java +++ b/graphics/java/android/renderscript/FieldPacker.java @@ -143,7 +143,7 @@ public class FieldPacker { public void addObj(BaseObj obj) { if (obj != null) { - addI32(obj.getID()); + addI32(obj.getID(null)); } else { addI32(0); } diff --git a/graphics/java/android/renderscript/FileA3D.java b/graphics/java/android/renderscript/FileA3D.java index b5419a7..6179317 100644 --- a/graphics/java/android/renderscript/FileA3D.java +++ b/graphics/java/android/renderscript/FileA3D.java @@ -165,7 +165,7 @@ public class FileA3D extends BaseObj { } private void initEntries() { - int numFileEntries = mRS.nFileA3DGetNumIndexEntries(getID()); + int numFileEntries = mRS.nFileA3DGetNumIndexEntries(getID(mRS)); if(numFileEntries <= 0) { return; } @@ -174,10 +174,10 @@ public class FileA3D extends BaseObj { int[] ids = new int[numFileEntries]; String[] names = new String[numFileEntries]; - mRS.nFileA3DGetIndexEntries(getID(), numFileEntries, ids, names); + mRS.nFileA3DGetIndexEntries(getID(mRS), numFileEntries, ids, names); for(int i = 0; i < numFileEntries; i ++) { - mFileEntries[i] = new IndexEntry(mRS, i, getID(), names[i], EntryType.toEntryType(ids[i])); + mFileEntries[i] = new IndexEntry(mRS, i, getID(mRS), names[i], EntryType.toEntryType(ids[i])); } } diff --git a/graphics/java/android/renderscript/Mesh.java b/graphics/java/android/renderscript/Mesh.java index 7ffaaf9e..ffbb41d 100644 --- a/graphics/java/android/renderscript/Mesh.java +++ b/graphics/java/android/renderscript/Mesh.java @@ -137,15 +137,15 @@ public class Mesh extends BaseObj { @Override void updateFromNative() { super.updateFromNative(); - int vtxCount = mRS.nMeshGetVertexBufferCount(getID()); - int idxCount = mRS.nMeshGetIndexCount(getID()); + int vtxCount = mRS.nMeshGetVertexBufferCount(getID(mRS)); + int idxCount = mRS.nMeshGetIndexCount(getID(mRS)); int[] vtxIDs = new int[vtxCount]; int[] idxIDs = new int[idxCount]; int[] primitives = new int[idxCount]; - mRS.nMeshGetVertices(getID(), vtxIDs, vtxCount); - mRS.nMeshGetIndices(getID(), idxIDs, primitives, idxCount); + mRS.nMeshGetVertices(getID(mRS), vtxIDs, vtxCount); + mRS.nMeshGetIndices(getID(mRS), idxIDs, primitives, idxCount); mVertexBuffers = new Allocation[vtxCount]; mIndexBuffers = new Allocation[idxCount]; @@ -343,7 +343,7 @@ public class Mesh extends BaseObj { alloc = Allocation.createSized(mRS, entry.e, entry.size, mUsage); } vertexBuffers[ct] = alloc; - vtx[ct] = alloc.getID(); + vtx[ct] = alloc.getID(mRS); } for(int ct = 0; ct < mIndexTypes.size(); ct ++) { @@ -354,7 +354,7 @@ public class Mesh extends BaseObj { } else if(entry.e != null) { alloc = Allocation.createSized(mRS, entry.e, entry.size, mUsage); } - int allocID = (alloc == null) ? 0 : alloc.getID(); + int allocID = (alloc == null) ? 0 : alloc.getID(mRS); indexBuffers[ct] = alloc; primitives[ct] = entry.prim; @@ -483,12 +483,12 @@ public class Mesh extends BaseObj { for(int ct = 0; ct < mVertexTypeCount; ct ++) { Entry entry = mVertexTypes[ct]; vertexBuffers[ct] = entry.a; - vtx[ct] = entry.a.getID(); + vtx[ct] = entry.a.getID(mRS); } for(int ct = 0; ct < mIndexTypes.size(); ct ++) { Entry entry = (Entry)mIndexTypes.elementAt(ct); - int allocID = (entry.a == null) ? 0 : entry.a.getID(); + int allocID = (entry.a == null) ? 0 : entry.a.getID(mRS); indexBuffers[ct] = entry.a; primitives[ct] = entry.prim; @@ -514,6 +514,7 @@ public class Mesh extends BaseObj { public static class TriangleMeshBuilder { float mVtxData[]; int mVtxCount; + int mMaxIndex; short mIndexData[]; int mIndexCount; RenderScript mRS; @@ -548,6 +549,7 @@ public class Mesh extends BaseObj { public TriangleMeshBuilder(RenderScript rs, int vtxSize, int flags) { mRS = rs; mVtxCount = 0; + mMaxIndex = 0; mIndexCount = 0; mVtxData = new float[128]; mIndexData = new short[128]; @@ -581,11 +583,13 @@ public class Mesh extends BaseObj { mVtxData[mVtxCount++] = mT0; } if ((mFlags & NORMAL) != 0) { - makeSpace(3); + makeSpace(4); mVtxData[mVtxCount++] = mNX; mVtxData[mVtxCount++] = mNY; mVtxData[mVtxCount++] = mNZ; + mVtxData[mVtxCount++] = 0.0f; } + mMaxIndex ++; } /** @@ -622,10 +626,11 @@ public class Mesh extends BaseObj { if (mVtxSize != 3) { throw new IllegalStateException("add mistmatch with declared components."); } - makeSpace(3); + makeSpace(4); mVtxData[mVtxCount++] = x; mVtxData[mVtxCount++] = y; mVtxData[mVtxCount++] = z; + mVtxData[mVtxCount++] = 1.0f; latch(); return this; } @@ -697,9 +702,9 @@ public class Mesh extends BaseObj { * @return this **/ public TriangleMeshBuilder addTriangle(int idx1, int idx2, int idx3) { - if((idx1 >= mVtxCount) || (idx1 < 0) || - (idx2 >= mVtxCount) || (idx2 < 0) || - (idx3 >= mVtxCount) || (idx3 < 0)) { + if((idx1 >= mMaxIndex) || (idx1 < 0) || + (idx2 >= mMaxIndex) || (idx2 < 0) || + (idx3 >= mMaxIndex) || (idx3 < 0)) { throw new IllegalStateException("Index provided greater than vertex count."); } if ((mIndexCount + 3) >= mIndexData.length) { @@ -729,20 +734,16 @@ public class Mesh extends BaseObj { **/ public Mesh create(boolean uploadToBufferObject) { Element.Builder b = new Element.Builder(mRS); - int floatCount = mVtxSize; b.add(Element.createVector(mRS, Element.DataType.FLOAT_32, mVtxSize), "position"); if ((mFlags & COLOR) != 0) { - floatCount += 4; b.add(Element.F32_4(mRS), "color"); } if ((mFlags & TEXTURE_0) != 0) { - floatCount += 2; b.add(Element.F32_2(mRS), "texture0"); } if ((mFlags & NORMAL) != 0) { - floatCount += 3; b.add(Element.F32_3(mRS), "normal"); } mElement = b.create(); @@ -753,12 +754,12 @@ public class Mesh extends BaseObj { } Builder smb = new Builder(mRS, usage); - smb.addVertexType(mElement, mVtxCount / floatCount); + smb.addVertexType(mElement, mMaxIndex); smb.addIndexSetType(Element.U16(mRS), mIndexCount, Primitive.TRIANGLE); Mesh sm = smb.create(); - sm.getVertexAllocation(0).copy1DRangeFromUnchecked(0, mVtxCount / floatCount, mVtxData); + sm.getVertexAllocation(0).copy1DRangeFromUnchecked(0, mMaxIndex, mVtxData); if(uploadToBufferObject) { if (uploadToBufferObject) { sm.getVertexAllocation(0).syncAll(Allocation.USAGE_SCRIPT); diff --git a/graphics/java/android/renderscript/Path.java b/graphics/java/android/renderscript/Path.java new file mode 100644 index 0000000..9c4d41b --- /dev/null +++ b/graphics/java/android/renderscript/Path.java @@ -0,0 +1,90 @@ +/* + * 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.util.Vector; +import android.util.Log; + +/** + * @hide + * + */ +public class Path extends BaseObj { + + public enum Primitive { + QUADRATIC_BEZIER(0), + CUBIC_BEZIER(1); + + int mID; + Primitive(int id) { + mID = id; + } + } + + Allocation mVertexBuffer; + Allocation mLoopBuffer; + Primitive mPrimitive; + float mQuality; + boolean mCoverageToAlpha; + + Path(int id, RenderScript rs, Primitive p, Allocation vtx, Allocation loop, float q) { + super(id, rs); + mVertexBuffer = vtx; + mLoopBuffer = loop; + mPrimitive = p; + mQuality = q; + } + + public Allocation getVertexAllocation() { + return mVertexBuffer; + } + + public Allocation getLoopAllocation() { + return mLoopBuffer; + } + + public Primitive getPrimitive() { + return mPrimitive; + } + + @Override + void updateFromNative() { + } + + + public static Path createStaticPath(RenderScript rs, Primitive p, float quality, Allocation vtx) { + int id = rs.nPathCreate(p.mID, false, vtx.getID(rs), 0, quality); + Path newPath = new Path(id, rs, p, null, null, quality); + return newPath; + } + + public static Path createStaticPath(RenderScript rs, Primitive p, float quality, Allocation vtx, Allocation loops) { + return null; + } + + public static Path createDynamicPath(RenderScript rs, Primitive p, float quality, Allocation vtx) { + return null; + } + + public static Path createDynamicPath(RenderScript rs, Primitive p, float quality, Allocation vtx, Allocation loops) { + return null; + } + + +} + + diff --git a/graphics/java/android/renderscript/Program.java b/graphics/java/android/renderscript/Program.java index a1b1ba3..104d1cd 100644 --- a/graphics/java/android/renderscript/Program.java +++ b/graphics/java/android/renderscript/Program.java @@ -69,6 +69,7 @@ public class Program extends BaseObj { Element mOutputs[]; Type mConstants[]; TextureType mTextures[]; + String mTextureNames[]; int mTextureCount; String mShader; @@ -77,6 +78,50 @@ public class Program extends BaseObj { } /** + * @hide + */ + public int getConstantCount() { + return mConstants != null ? mConstants.length : 0; + } + + /** + * @hide + */ + public Type getConstant(int slot) { + if (slot < 0 || slot >= mConstants.length) { + throw new IllegalArgumentException("Slot ID out of range."); + } + return mConstants[slot]; + } + + /** + * @hide + */ + public int getTextureCount() { + return mTextureCount; + } + + /** + * @hide + */ + public TextureType getTextureType(int slot) { + if ((slot < 0) || (slot >= mTextureCount)) { + throw new IllegalArgumentException("Slot ID out of range."); + } + return mTextures[slot]; + } + + /** + * @hide + */ + public String getTextureName(int slot) { + if ((slot < 0) || (slot >= mTextureCount)) { + throw new IllegalArgumentException("Slot ID out of range."); + } + return mTextureNames[slot]; + } + + /** * Binds a constant buffer to be used as uniform inputs to the * program * @@ -89,11 +134,11 @@ public class Program extends BaseObj { throw new IllegalArgumentException("Slot ID out of range."); } if (a != null && - a.getType().getID() != mConstants[slot].getID()) { + a.getType().getID(mRS) != mConstants[slot].getID(mRS)) { throw new IllegalArgumentException("Allocation type does not match slot type."); } - int id = a != null ? a.getID() : 0; - mRS.nProgramBindConstants(getID(), slot, id); + int id = a != null ? a.getID(mRS) : 0; + mRS.nProgramBindConstants(getID(mRS), slot, id); } /** @@ -114,8 +159,8 @@ public class Program extends BaseObj { throw new IllegalArgumentException("Cannot bind cubemap to 2d texture slot"); } - int id = va != null ? va.getID() : 0; - mRS.nProgramBindTexture(getID(), slot, id); + int id = va != null ? va.getID(mRS) : 0; + mRS.nProgramBindTexture(getID(mRS), slot, id); } /** @@ -134,8 +179,8 @@ public class Program extends BaseObj { throw new IllegalArgumentException("Slot ID out of range."); } - int id = vs != null ? vs.getID() : 0; - mRS.nProgramBindSampler(getID(), slot, id); + int id = vs != null ? vs.getID(mRS) : 0; + mRS.nProgramBindSampler(getID(mRS), slot, id); } @@ -146,6 +191,7 @@ public class Program extends BaseObj { Type mConstants[]; Type mTextures[]; TextureType mTextureTypes[]; + String mTextureNames[]; int mInputCount; int mOutputCount; int mConstantCount; @@ -163,6 +209,7 @@ public class Program extends BaseObj { mConstantCount = 0; mTextureCount = 0; mTextureTypes = new TextureType[MAX_TEXTURE]; + mTextureNames = new String[MAX_TEXTURE]; } /** @@ -266,10 +313,28 @@ public class Program extends BaseObj { * @return self */ public BaseProgramBuilder addTexture(TextureType texType) throws IllegalArgumentException { + addTexture(texType, "Tex" + mTextureCount); + return this; + } + + /** + * @hide + * Adds a texture input to the Program + * + * @param texType describes that the texture to append it (2D, + * Cubemap, etc.) + * @param texName what the texture should be called in the + * shader + * @return self + */ + public BaseProgramBuilder addTexture(TextureType texType, String texName) + throws IllegalArgumentException { if(mTextureCount >= MAX_TEXTURE) { throw new IllegalArgumentException("Max texture count exceeded."); } - mTextureTypes[mTextureCount ++] = texType; + mTextureTypes[mTextureCount] = texType; + mTextureNames[mTextureCount] = texName; + mTextureCount ++; return this; } @@ -283,6 +348,8 @@ public class Program extends BaseObj { p.mTextureCount = mTextureCount; p.mTextures = new TextureType[mTextureCount]; System.arraycopy(mTextureTypes, 0, p.mTextures, 0, mTextureCount); + p.mTextureNames = new String[mTextureCount]; + System.arraycopy(mTextureNames, 0, p.mTextureNames, 0, mTextureCount); } } diff --git a/graphics/java/android/renderscript/ProgramFragment.java b/graphics/java/android/renderscript/ProgramFragment.java index 21bace8..fa6e2d4 100644 --- a/graphics/java/android/renderscript/ProgramFragment.java +++ b/graphics/java/android/renderscript/ProgramFragment.java @@ -59,26 +59,28 @@ public class ProgramFragment extends Program { public ProgramFragment create() { mRS.validate(); int[] tmp = new int[(mInputCount + mOutputCount + mConstantCount + mTextureCount) * 2]; + String[] texNames = new String[mTextureCount]; int idx = 0; for (int i=0; i < mInputCount; i++) { tmp[idx++] = ProgramParam.INPUT.mID; - tmp[idx++] = mInputs[i].getID(); + tmp[idx++] = mInputs[i].getID(mRS); } for (int i=0; i < mOutputCount; i++) { tmp[idx++] = ProgramParam.OUTPUT.mID; - tmp[idx++] = mOutputs[i].getID(); + tmp[idx++] = mOutputs[i].getID(mRS); } for (int i=0; i < mConstantCount; i++) { tmp[idx++] = ProgramParam.CONSTANT.mID; - tmp[idx++] = mConstants[i].getID(); + tmp[idx++] = mConstants[i].getID(mRS); } for (int i=0; i < mTextureCount; i++) { tmp[idx++] = ProgramParam.TEXTURE_TYPE.mID; tmp[idx++] = mTextureTypes[i].mID; + texNames[i] = mTextureNames[i]; } - int id = mRS.nProgramFragmentCreate(mShader, tmp); + int id = mRS.nProgramFragmentCreate(mShader, texNames, tmp); ProgramFragment pf = new ProgramFragment(id, mRS); initProgram(pf); return pf; diff --git a/graphics/java/android/renderscript/ProgramFragmentFixedFunction.java b/graphics/java/android/renderscript/ProgramFragmentFixedFunction.java index 0ab73c1..14f10f1 100644 --- a/graphics/java/android/renderscript/ProgramFragmentFixedFunction.java +++ b/graphics/java/android/renderscript/ProgramFragmentFixedFunction.java @@ -47,26 +47,28 @@ public class ProgramFragmentFixedFunction extends ProgramFragment { public ProgramFragmentFixedFunction create() { mRS.validate(); int[] tmp = new int[(mInputCount + mOutputCount + mConstantCount + mTextureCount) * 2]; + String[] texNames = new String[mTextureCount]; int idx = 0; for (int i=0; i < mInputCount; i++) { tmp[idx++] = ProgramParam.INPUT.mID; - tmp[idx++] = mInputs[i].getID(); + tmp[idx++] = mInputs[i].getID(mRS); } for (int i=0; i < mOutputCount; i++) { tmp[idx++] = ProgramParam.OUTPUT.mID; - tmp[idx++] = mOutputs[i].getID(); + tmp[idx++] = mOutputs[i].getID(mRS); } for (int i=0; i < mConstantCount; i++) { tmp[idx++] = ProgramParam.CONSTANT.mID; - tmp[idx++] = mConstants[i].getID(); + tmp[idx++] = mConstants[i].getID(mRS); } for (int i=0; i < mTextureCount; i++) { tmp[idx++] = ProgramParam.TEXTURE_TYPE.mID; tmp[idx++] = mTextureTypes[i].mID; + texNames[i] = mTextureNames[i]; } - int id = mRS.nProgramFragmentCreate(mShader, tmp); + int id = mRS.nProgramFragmentCreate(mShader, texNames, tmp); ProgramFragmentFixedFunction pf = new ProgramFragmentFixedFunction(id, mRS); initProgram(pf); return pf; diff --git a/graphics/java/android/renderscript/ProgramVertex.java b/graphics/java/android/renderscript/ProgramVertex.java index 56bb836..32c908e 100644 --- a/graphics/java/android/renderscript/ProgramVertex.java +++ b/graphics/java/android/renderscript/ProgramVertex.java @@ -55,6 +55,23 @@ public class ProgramVertex extends Program { } /** + * @hide + */ + public int getInputCount() { + return mInputs != null ? mInputs.length : 0; + } + + /** + * @hide + */ + public Element getInput(int slot) { + if (slot < 0 || slot >= mInputs.length) { + throw new IllegalArgumentException("Slot ID out of range."); + } + return mInputs[slot]; + } + + /** * Builder class for creating ProgramVertex objects. * The builder starts empty and the user must minimally provide * the GLSL shader code, and the varying inputs. Constant, or @@ -99,26 +116,28 @@ public class ProgramVertex extends Program { public ProgramVertex create() { mRS.validate(); int[] tmp = new int[(mInputCount + mOutputCount + mConstantCount + mTextureCount) * 2]; + String[] texNames = new String[mTextureCount]; int idx = 0; for (int i=0; i < mInputCount; i++) { tmp[idx++] = ProgramParam.INPUT.mID; - tmp[idx++] = mInputs[i].getID(); + tmp[idx++] = mInputs[i].getID(mRS); } for (int i=0; i < mOutputCount; i++) { tmp[idx++] = ProgramParam.OUTPUT.mID; - tmp[idx++] = mOutputs[i].getID(); + tmp[idx++] = mOutputs[i].getID(mRS); } for (int i=0; i < mConstantCount; i++) { tmp[idx++] = ProgramParam.CONSTANT.mID; - tmp[idx++] = mConstants[i].getID(); + tmp[idx++] = mConstants[i].getID(mRS); } for (int i=0; i < mTextureCount; i++) { tmp[idx++] = ProgramParam.TEXTURE_TYPE.mID; tmp[idx++] = mTextureTypes[i].mID; + texNames[i] = mTextureNames[i]; } - int id = mRS.nProgramVertexCreate(mShader, tmp); + int id = mRS.nProgramVertexCreate(mShader, texNames, tmp); ProgramVertex pv = new ProgramVertex(id, mRS); initProgram(pv); return pv; diff --git a/graphics/java/android/renderscript/ProgramVertexFixedFunction.java b/graphics/java/android/renderscript/ProgramVertexFixedFunction.java index 740d6a5..fac4c3d 100644 --- a/graphics/java/android/renderscript/ProgramVertexFixedFunction.java +++ b/graphics/java/android/renderscript/ProgramVertexFixedFunction.java @@ -70,26 +70,28 @@ public class ProgramVertexFixedFunction extends ProgramVertex { public ProgramVertexFixedFunction create() { mRS.validate(); int[] tmp = new int[(mInputCount + mOutputCount + mConstantCount + mTextureCount) * 2]; + String[] texNames = new String[mTextureCount]; int idx = 0; for (int i=0; i < mInputCount; i++) { tmp[idx++] = ProgramParam.INPUT.mID; - tmp[idx++] = mInputs[i].getID(); + tmp[idx++] = mInputs[i].getID(mRS); } for (int i=0; i < mOutputCount; i++) { tmp[idx++] = ProgramParam.OUTPUT.mID; - tmp[idx++] = mOutputs[i].getID(); + tmp[idx++] = mOutputs[i].getID(mRS); } for (int i=0; i < mConstantCount; i++) { tmp[idx++] = ProgramParam.CONSTANT.mID; - tmp[idx++] = mConstants[i].getID(); + tmp[idx++] = mConstants[i].getID(mRS); } for (int i=0; i < mTextureCount; i++) { tmp[idx++] = ProgramParam.TEXTURE_TYPE.mID; tmp[idx++] = mTextureTypes[i].mID; + texNames[i] = mTextureNames[i]; } - int id = mRS.nProgramVertexCreate(mShader, tmp); + int id = mRS.nProgramVertexCreate(mShader, texNames, tmp); ProgramVertexFixedFunction pv = new ProgramVertexFixedFunction(id, mRS); initProgram(pv); return pv; diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java index ad10832..03294b5 100644 --- a/graphics/java/android/renderscript/RenderScript.java +++ b/graphics/java/android/renderscript/RenderScript.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 The Android Open Source Project + * Copyright (C) 2008-2012 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. @@ -16,6 +16,7 @@ package android.renderscript; +import java.io.File; import java.lang.reflect.Field; import android.content.Context; @@ -82,6 +83,25 @@ public class RenderScript { native void nContextInitToClient(int con); native void nContextDeinitToClient(int con); + /** + * Name of the file that holds the object cache. + */ + private static final String CACHE_PATH = "com.android.renderscript.cache"; + static String mCachePath; + + /** + * Sets the directory to use as a persistent storage for the + * renderscript object file cache. + * + * @hide + * @param cacheDir A directory the current process can write to + */ + public static void setupDiskCache(File cacheDir) { + File f = new File(cacheDir, CACHE_PATH); + mCachePath = f.getAbsolutePath(); + f.mkdirs(); + } + // Methods below are wrapped to protect the non-threadsafe // lockless fifo. @@ -231,10 +251,10 @@ public class RenderScript { rsnTypeGetNativeData(mContext, id, typeData); } - native int rsnAllocationCreateTyped(int con, int type, int mip, int usage); - synchronized int nAllocationCreateTyped(int type, int mip, int usage) { + native int rsnAllocationCreateTyped(int con, int type, int mip, int usage, int pointer); + synchronized int nAllocationCreateTyped(int type, int mip, int usage, int pointer) { validate(); - return rsnAllocationCreateTyped(mContext, type, mip, usage); + return rsnAllocationCreateTyped(mContext, type, mip, usage, pointer); } native int rsnAllocationCreateFromBitmap(int con, int type, int mip, Bitmap bmp, int usage); synchronized int nAllocationCreateFromBitmap(int type, int mip, Bitmap bmp, int usage) { @@ -269,6 +289,33 @@ public class RenderScript { validate(); rsnAllocationSyncAll(mContext, alloc, src); } + native int rsnAllocationGetSurfaceTextureID(int con, int alloc); + synchronized int nAllocationGetSurfaceTextureID(int alloc) { + validate(); + return rsnAllocationGetSurfaceTextureID(mContext, alloc); + } + native void rsnAllocationGetSurfaceTextureID2(int con, int alloc, SurfaceTexture st); + synchronized void nAllocationGetSurfaceTextureID2(int alloc, SurfaceTexture st) { + validate(); + rsnAllocationGetSurfaceTextureID2(mContext, alloc, st); + } + native void rsnAllocationSetSurface(int con, int alloc, Surface sur); + synchronized void nAllocationSetSurface(int alloc, Surface sur) { + validate(); + rsnAllocationSetSurface(mContext, alloc, sur); + } + native void rsnAllocationIoSend(int con, int alloc); + synchronized void nAllocationIoSend(int alloc) { + validate(); + rsnAllocationIoSend(mContext, alloc); + } + native void rsnAllocationIoReceive(int con, int alloc); + synchronized void nAllocationIoReceive(int alloc) { + validate(); + rsnAllocationIoReceive(mContext, alloc); + } + + native void rsnAllocationGenerateMipmaps(int con, int alloc); synchronized void nAllocationGenerateMipmaps(int alloc) { validate(); @@ -547,15 +594,15 @@ public class RenderScript { validate(); rsnProgramBindSampler(mContext, vpf, slot, s); } - native int rsnProgramFragmentCreate(int con, String shader, int[] params); - synchronized int nProgramFragmentCreate(String shader, int[] params) { + native int rsnProgramFragmentCreate(int con, String shader, String[] texNames, int[] params); + synchronized int nProgramFragmentCreate(String shader, String[] texNames, int[] params) { validate(); - return rsnProgramFragmentCreate(mContext, shader, params); + return rsnProgramFragmentCreate(mContext, shader, texNames, params); } - native int rsnProgramVertexCreate(int con, String shader, int[] params); - synchronized int nProgramVertexCreate(String shader, int[] params) { + native int rsnProgramVertexCreate(int con, String shader, String[] texNames, int[] params); + synchronized int nProgramVertexCreate(String shader, String[] texNames, int[] params) { validate(); - return rsnProgramVertexCreate(mContext, shader, params); + return rsnProgramVertexCreate(mContext, shader, texNames, params); } native int rsnMeshCreate(int con, int[] vtx, int[] idx, int[] prim); @@ -584,6 +631,11 @@ public class RenderScript { rsnMeshGetIndices(mContext, id, idxIds, primitives, vtxIdCount); } + native int rsnPathCreate(int con, int prim, boolean isStatic, int vtx, int loop, float q); + synchronized int nPathCreate(int prim, boolean isStatic, int vtx, int loop, float q) { + validate(); + return rsnPathCreate(mContext, prim, isStatic, vtx, loop, q); + } int mDev; int mContext; @@ -837,7 +889,8 @@ public class RenderScript { mRS.mErrorCallback.mErrorNum = subID; mRS.mErrorCallback.run(); } else { - //throw new RSRuntimeException("Received error num " + subID + ", details: " + e); + // Do not throw here. In these cases, we do not have + // a fatal error. } continue; } @@ -856,7 +909,9 @@ public class RenderScript { } RenderScript(Context ctx) { - mApplicationContext = ctx.getApplicationContext(); + if (ctx != null) { + mApplicationContext = ctx.getApplicationContext(); + } } /** @@ -868,21 +923,16 @@ public class RenderScript { return mApplicationContext; } - static int getTargetSdkVersion(Context ctx) { - return ctx.getApplicationInfo().targetSdkVersion; - } - /** * Create a basic RenderScript context. * + * @hide * @param ctx The context. * @return RenderScript */ - public static RenderScript create(Context ctx) { + public static RenderScript create(Context ctx, int sdkVersion) { RenderScript rs = new RenderScript(ctx); - int sdkVersion = getTargetSdkVersion(ctx); - rs.mDev = rs.nDeviceCreate(); rs.mContext = rs.nContextCreate(rs.mDev, 0, sdkVersion); if (rs.mContext == 0) { @@ -894,6 +944,17 @@ public class RenderScript { } /** + * Create a basic RenderScript context. + * + * @param ctx The context. + * @return RenderScript + */ + public static RenderScript create(Context ctx) { + int v = ctx.getApplicationInfo().targetSdkVersion; + return create(ctx, v); + } + + /** * Print the currently available debugging information about the state of * the RS context to the log. * @@ -939,7 +1000,7 @@ public class RenderScript { int safeID(BaseObj o) { if(o != null) { - return o.getID(); + return o.getID(this); } return 0; } diff --git a/graphics/java/android/renderscript/RenderScriptGL.java b/graphics/java/android/renderscript/RenderScriptGL.java index 2cfeb17..1b2ac90 100644 --- a/graphics/java/android/renderscript/RenderScriptGL.java +++ b/graphics/java/android/renderscript/RenderScriptGL.java @@ -166,7 +166,7 @@ public class RenderScriptGL extends RenderScript { super(ctx); mSurfaceConfig = new SurfaceConfig(sc); - int sdkVersion = getTargetSdkVersion(ctx); + int sdkVersion = ctx.getApplicationInfo().targetSdkVersion; mWidth = 0; mHeight = 0; diff --git a/graphics/java/android/renderscript/Script.java b/graphics/java/android/renderscript/Script.java index d00c428..4f59ae3 100644 --- a/graphics/java/android/renderscript/Script.java +++ b/graphics/java/android/renderscript/Script.java @@ -26,7 +26,7 @@ public class Script extends BaseObj { * @param slot */ protected void invoke(int slot) { - mRS.nScriptInvoke(getID(), slot); + mRS.nScriptInvoke(getID(mRS), slot); } /** @@ -37,9 +37,9 @@ public class Script extends BaseObj { */ protected void invoke(int slot, FieldPacker v) { if (v != null) { - mRS.nScriptInvokeV(getID(), slot, v.getData()); + mRS.nScriptInvokeV(getID(mRS), slot, v.getData()); } else { - mRS.nScriptInvoke(getID(), slot); + mRS.nScriptInvoke(getID(mRS), slot); } } @@ -58,17 +58,17 @@ public class Script extends BaseObj { } int in_id = 0; if (ain != null) { - in_id = ain.getID(); + in_id = ain.getID(mRS); } int out_id = 0; if (aout != null) { - out_id = aout.getID(); + out_id = aout.getID(mRS); } byte[] params = null; if (v != null) { params = v.getData(); } - mRS.nScriptForEach(getID(), slot, in_id, out_id, params); + mRS.nScriptForEach(getID(mRS), slot, in_id, out_id, params); } @@ -86,9 +86,9 @@ public class Script extends BaseObj { public void bindAllocation(Allocation va, int slot) { mRS.validate(); if (va != null) { - mRS.nScriptBindAllocation(getID(), va.getID(), slot); + mRS.nScriptBindAllocation(getID(mRS), va.getID(mRS), slot); } else { - mRS.nScriptBindAllocation(getID(), 0, slot); + mRS.nScriptBindAllocation(getID(mRS), 0, slot); } } @@ -99,7 +99,7 @@ public class Script extends BaseObj { * @param v */ public void setVar(int index, float v) { - mRS.nScriptSetVarF(getID(), index, v); + mRS.nScriptSetVarF(getID(mRS), index, v); } /** @@ -109,7 +109,7 @@ public class Script extends BaseObj { * @param v */ public void setVar(int index, double v) { - mRS.nScriptSetVarD(getID(), index, v); + mRS.nScriptSetVarD(getID(mRS), index, v); } /** @@ -119,7 +119,7 @@ public class Script extends BaseObj { * @param v */ public void setVar(int index, int v) { - mRS.nScriptSetVarI(getID(), index, v); + mRS.nScriptSetVarI(getID(mRS), index, v); } /** @@ -129,7 +129,7 @@ public class Script extends BaseObj { * @param v */ public void setVar(int index, long v) { - mRS.nScriptSetVarJ(getID(), index, v); + mRS.nScriptSetVarJ(getID(mRS), index, v); } /** @@ -139,7 +139,7 @@ public class Script extends BaseObj { * @param v */ public void setVar(int index, boolean v) { - mRS.nScriptSetVarI(getID(), index, v ? 1 : 0); + mRS.nScriptSetVarI(getID(mRS), index, v ? 1 : 0); } /** @@ -149,7 +149,7 @@ public class Script extends BaseObj { * @param o */ public void setVar(int index, BaseObj o) { - mRS.nScriptSetVarObj(getID(), index, (o == null) ? 0 : o.getID()); + mRS.nScriptSetVarObj(getID(mRS), index, (o == null) ? 0 : o.getID(mRS)); } /** @@ -159,13 +159,13 @@ public class Script extends BaseObj { * @param v */ public void setVar(int index, FieldPacker v) { - mRS.nScriptSetVarV(getID(), index, v.getData()); + mRS.nScriptSetVarV(getID(mRS), index, v.getData()); } public void setTimeZone(String timeZone) { mRS.validate(); try { - mRS.nScriptSetTimeZone(getID(), timeZone.getBytes("UTF-8")); + mRS.nScriptSetTimeZone(getID(mRS), timeZone.getBytes("UTF-8")); } catch (java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } diff --git a/graphics/java/android/renderscript/ScriptC.java b/graphics/java/android/renderscript/ScriptC.java index 90f959f..108b230 100644 --- a/graphics/java/android/renderscript/ScriptC.java +++ b/graphics/java/android/renderscript/ScriptC.java @@ -92,13 +92,9 @@ public class ScriptC extends Script { throw new Resources.NotFoundException(); } - // E.g, /system/apps/Fountain.apk - //String packageName = rs.getApplicationContext().getPackageResourcePath(); - // For res/raw/fountain.bc, it wil be /com.android.fountain:raw/fountain String resName = resources.getResourceEntryName(resourceID); - String cacheDir = rs.getApplicationContext().getCacheDir().toString(); Log.v(TAG, "Create script for resource = " + resName); - return rs.nScriptCCreate(resName, cacheDir, pgm, pgmLength); + return rs.nScriptCCreate(resName, rs.mCachePath, pgm, pgmLength); } } diff --git a/graphics/java/android/renderscript/Type.java b/graphics/java/android/renderscript/Type.java index 70d1de4..a707df2 100644 --- a/graphics/java/android/renderscript/Type.java +++ b/graphics/java/android/renderscript/Type.java @@ -180,7 +180,7 @@ public class Type extends BaseObj { // We have 6 integer to obtain mDimX; mDimY; mDimZ; // mDimLOD; mDimFaces; mElement; int[] dataBuffer = new int[6]; - mRS.nTypeGetNativeData(getID(), dataBuffer); + mRS.nTypeGetNativeData(getID(mRS), dataBuffer); mDimX = dataBuffer[0]; mDimY = dataBuffer[1]; @@ -280,7 +280,8 @@ public class Type extends BaseObj { } } - int id = mRS.nTypeCreate(mElement.getID(), mDimX, mDimY, mDimZ, mDimMipmaps, mDimFaces); + int id = mRS.nTypeCreate(mElement.getID(mRS), + mDimX, mDimY, mDimZ, mDimMipmaps, mDimFaces); Type t = new Type(id, mRS); t.mElement = mElement; t.mDimX = mDimX; |
