diff options
Diffstat (limited to 'graphics/java/android')
17 files changed, 381 insertions, 148 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/Canvas.java b/graphics/java/android/graphics/Canvas.java index e1c73fd..dcda67d 100644 --- a/graphics/java/android/graphics/Canvas.java +++ b/graphics/java/android/graphics/Canvas.java @@ -130,8 +130,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 +360,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 +391,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 +495,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 +514,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 +523,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 +539,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 +552,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 +589,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 +606,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 +621,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 +755,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 +855,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 +878,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 +897,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 +936,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 +964,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 +990,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 +1029,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 +1070,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 +1101,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 +1132,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 +1154,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 +1184,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 +1238,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 +1256,7 @@ public class Canvas { verts, vertOffset, colors, colorOffset, paint != null ? paint.mNativePaint : 0); } - + public enum VertexMode { TRIANGLES(0), TRIANGLE_STRIP(1), @@ -1315,12 +1302,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 +1329,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 +1363,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 +1384,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 +1422,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 +1459,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 +1495,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 +1506,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 +1518,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 +1548,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 +1570,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 +1596,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 +1609,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/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..0ada1fb 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 diff --git a/graphics/java/android/graphics/RectF.java b/graphics/java/android/graphics/RectF.java index 00e9609..293dfcc 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; + + Rect r = (Rect) 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/drawable/AnimationDrawable.java b/graphics/java/android/graphics/drawable/AnimationDrawable.java index 07de074..4ad5b9f 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" /> @@ -221,6 +221,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/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/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java index f285f5b..11c2427 100644 --- a/graphics/java/android/renderscript/Allocation.java +++ b/graphics/java/android/renderscript/Allocation.java @@ -487,6 +487,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 + diff --git a/graphics/java/android/renderscript/Element.java b/graphics/java/android/renderscript/Element.java index d378a78..22ef7bb 100644 --- a/graphics/java/android/renderscript/Element.java +++ b/graphics/java/android/renderscript/Element.java @@ -696,7 +696,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; } @@ -891,6 +895,7 @@ public class Element extends BaseObj { String[] mElementNames; int[] mArraySizes; int mCount; + int mSkipPadding; /** * Create a builder object. @@ -916,6 +921,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]; diff --git a/graphics/java/android/renderscript/Mesh.java b/graphics/java/android/renderscript/Mesh.java index 7b3b73f..b6ca58c 100644 --- a/graphics/java/android/renderscript/Mesh.java +++ b/graphics/java/android/renderscript/Mesh.java @@ -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/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java index ad10832..bfe412c 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. @@ -837,7 +837,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; } |