summaryrefslogtreecommitdiffstats
path: root/graphics/java
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/java')
-rw-r--r--graphics/java/android/graphics/Bitmap.java3
-rw-r--r--graphics/java/android/graphics/Canvas.java58
-rw-r--r--graphics/java/android/graphics/ImageFormat.java14
-rw-r--r--graphics/java/android/graphics/Matrix.java182
-rw-r--r--graphics/java/android/graphics/Paint.java396
-rw-r--r--graphics/java/android/graphics/Path.java30
-rw-r--r--graphics/java/android/graphics/RectF.java31
-rw-r--r--graphics/java/android/graphics/SurfaceTexture.java83
-rw-r--r--graphics/java/android/graphics/Typeface.java2
-rw-r--r--graphics/java/android/graphics/drawable/AnimatedRotateDrawable.java27
-rw-r--r--graphics/java/android/graphics/drawable/AnimationDrawable.java7
-rw-r--r--graphics/java/android/graphics/drawable/BitmapDrawable.java105
-rw-r--r--graphics/java/android/graphics/drawable/ClipDrawable.java4
-rw-r--r--graphics/java/android/graphics/drawable/ColorDrawable.java5
-rw-r--r--graphics/java/android/graphics/drawable/Drawable.java29
-rw-r--r--graphics/java/android/graphics/drawable/DrawableContainer.java1
-rw-r--r--graphics/java/android/graphics/drawable/GradientDrawable.java4
-rw-r--r--graphics/java/android/graphics/drawable/LayerDrawable.java11
-rw-r--r--graphics/java/android/graphics/drawable/NinePatchDrawable.java6
-rw-r--r--graphics/java/android/graphics/drawable/RotateDrawable.java2
-rw-r--r--graphics/java/android/graphics/drawable/ScaleDrawable.java4
-rw-r--r--graphics/java/android/graphics/drawable/TransitionDrawable.java14
-rw-r--r--graphics/java/android/renderscript/Allocation.java223
-rw-r--r--graphics/java/android/renderscript/AllocationAdapter.java310
-rw-r--r--graphics/java/android/renderscript/BaseObj.java39
-rw-r--r--graphics/java/android/renderscript/Byte2.java5
-rw-r--r--graphics/java/android/renderscript/Byte3.java6
-rw-r--r--graphics/java/android/renderscript/Byte4.java7
-rw-r--r--graphics/java/android/renderscript/Double2.java43
-rw-r--r--graphics/java/android/renderscript/Double3.java45
-rw-r--r--graphics/java/android/renderscript/Double4.java46
-rw-r--r--graphics/java/android/renderscript/Element.java239
-rw-r--r--graphics/java/android/renderscript/FieldPacker.java63
-rw-r--r--graphics/java/android/renderscript/Font.java14
-rw-r--r--graphics/java/android/renderscript/Int2.java5
-rw-r--r--graphics/java/android/renderscript/Int3.java6
-rw-r--r--graphics/java/android/renderscript/Int4.java7
-rw-r--r--graphics/java/android/renderscript/Long2.java5
-rw-r--r--graphics/java/android/renderscript/Long3.java6
-rw-r--r--graphics/java/android/renderscript/Long4.java7
-rw-r--r--graphics/java/android/renderscript/Mesh.java127
-rw-r--r--graphics/java/android/renderscript/Program.java1
-rw-r--r--graphics/java/android/renderscript/ProgramFragment.java1
-rw-r--r--graphics/java/android/renderscript/ProgramFragmentFixedFunction.java1
-rw-r--r--graphics/java/android/renderscript/ProgramRaster.java24
-rw-r--r--graphics/java/android/renderscript/ProgramStore.java21
-rw-r--r--graphics/java/android/renderscript/ProgramVertex.java1
-rw-r--r--graphics/java/android/renderscript/ProgramVertexFixedFunction.java1
-rw-r--r--graphics/java/android/renderscript/RSTextureView.java179
-rw-r--r--graphics/java/android/renderscript/RenderScript.java244
-rw-r--r--graphics/java/android/renderscript/RenderScriptGL.java31
-rw-r--r--graphics/java/android/renderscript/Sampler.java16
-rw-r--r--graphics/java/android/renderscript/Script.java28
-rw-r--r--graphics/java/android/renderscript/ScriptC.java9
-rw-r--r--graphics/java/android/renderscript/Short2.java5
-rw-r--r--graphics/java/android/renderscript/Short3.java6
-rw-r--r--graphics/java/android/renderscript/Short4.java7
-rw-r--r--graphics/java/android/renderscript/Type.java14
-rw-r--r--graphics/java/com/android/internal/graphics/NativeUtils.java40
59 files changed, 2233 insertions, 617 deletions
diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java
index 40d54bb..79acd55 100644
--- a/graphics/java/android/graphics/Bitmap.java
+++ b/graphics/java/android/graphics/Bitmap.java
@@ -93,7 +93,7 @@ public final class Bitmap implements Parcelable {
This can be called from JNI code.
*/
- private Bitmap(int nativeBitmap, byte[] buffer, boolean isMutable, byte[] ninePatchChunk,
+ /*package*/ Bitmap(int nativeBitmap, byte[] buffer, boolean isMutable, byte[] ninePatchChunk,
int density) {
if (nativeBitmap == 0) {
throw new RuntimeException("internal error: native bitmap is 0");
@@ -567,6 +567,7 @@ public final class Bitmap implements Parcelable {
canvas.setBitmap(bitmap);
canvas.drawBitmap(source, srcR, dstR, paint);
+ canvas.setBitmap(null);
return bitmap;
}
diff --git a/graphics/java/android/graphics/Canvas.java b/graphics/java/android/graphics/Canvas.java
index 965abe9..eefd21e 100644
--- a/graphics/java/android/graphics/Canvas.java
+++ b/graphics/java/android/graphics/Canvas.java
@@ -73,7 +73,11 @@ public class Canvas {
* @hide
*/
public static final int DIRECTION_RTL = 1;
-
+
+ // Maximum bitmap size as defined in Skia's native code
+ // (see SkCanvas.cpp, SkDraw.cpp)
+ private static final int MAXMIMUM_BITMAP_SIZE = 32766;
+
// This field is used to finalize the native Canvas properly
@SuppressWarnings({"UnusedDeclaration"})
private final CanvasFinalizer mFinalizer;
@@ -174,17 +178,22 @@ public class Canvas {
* @see #getDensity()
*/
public void setBitmap(Bitmap bitmap) {
- if (!bitmap.isMutable()) {
- throw new IllegalStateException();
- }
if (isHardwareAccelerated()) {
throw new RuntimeException("Can't set a bitmap device on a GL canvas");
}
- throwIfRecycled(bitmap);
- native_setBitmap(mNativeCanvas, bitmap.ni());
+ int pointer = 0;
+ if (bitmap != null) {
+ if (!bitmap.isMutable()) {
+ throw new IllegalStateException();
+ }
+ throwIfRecycled(bitmap);
+ mDensity = bitmap.mDensity;
+ pointer = bitmap.ni();
+ }
+
+ native_setBitmap(mNativeCanvas, pointer);
mBitmap = bitmap;
- mDensity = bitmap.mDensity;
}
/**
@@ -259,7 +268,29 @@ public class Canvas {
public void setScreenDensity(int density) {
mScreenDensity = density;
}
+
+ /**
+ * Returns the maximum allowed width for bitmaps drawn with this canvas.
+ * Attempting to draw with a bitmap wider than this value will result
+ * in an error.
+ *
+ * @see #getMaximumBitmapHeight()
+ */
+ public int getMaximumBitmapWidth() {
+ return MAXMIMUM_BITMAP_SIZE;
+ }
+ /**
+ * Returns the maximum allowed height for bitmaps drawn with this canvas.
+ * Attempting to draw with a bitmap taller than this value will result
+ * in an error.
+ *
+ * @see #getMaximumBitmapWidth()
+ */
+ public int getMaximumBitmapHeight() {
+ return MAXMIMUM_BITMAP_SIZE;
+ }
+
// the SAVE_FLAG constants must match their native equivalents
/** restore the current matrix when restore() is called */
@@ -477,17 +508,6 @@ public class Canvas {
}
/**
- * Returns a pointer to an internal 4x4 native matrix. The returned
- * pointer is a pointer to an array of 16 floats.
- *
- * @hide
- */
- @SuppressWarnings({"UnusedDeclaration"})
- public int getNativeMatrix() {
- return 0;
- }
-
- /**
* Return a new matrix with a copy of the canvas' current transformation
* matrix.
*/
@@ -1388,7 +1408,7 @@ public class Canvas {
} else {
char[] buf = TemporaryBuffer.obtain(end - start);
TextUtils.getChars(text, start, end, buf, 0);
- native_drawText(mNativeCanvas, buf, 0, end - start, x, y,
+ native_drawText(mNativeCanvas, buf, 0, end - start, x, y,
paint.mBidiFlags, paint.mNativePaint);
TemporaryBuffer.recycle(buf);
}
diff --git a/graphics/java/android/graphics/ImageFormat.java b/graphics/java/android/graphics/ImageFormat.java
index b8e9384..7269a71 100644
--- a/graphics/java/android/graphics/ImageFormat.java
+++ b/graphics/java/android/graphics/ImageFormat.java
@@ -84,9 +84,19 @@ public class ImageFormat {
public static final int JPEG = 0x100;
/**
+ * Raw bayer format used for images, which is 10 bit precision samples
+ * stored in 16 bit words. The filter pattern is RGGB. Whether this format
+ * is supported by the camera hardware can be determined by
+ * {@link android.hardware.Camera.Parameters#getSupportedPreviewFormats()}.
+ *
+ * @hide
+ */
+ public static final int BAYER_RGGB = 0x200;
+
+ /**
* Use this function to retrieve the number of bits per pixel of an
* ImageFormat.
- *
+ *
* @param format
* @return the number of bits per pixel of the given format or -1 if the
* format doesn't exist or is not supported.
@@ -103,6 +113,8 @@ public class ImageFormat {
return 12;
case NV21:
return 12;
+ case BAYER_RGGB:
+ return 16;
}
return -1;
}
diff --git a/graphics/java/android/graphics/Matrix.java b/graphics/java/android/graphics/Matrix.java
index 66ed104..a837294 100644
--- a/graphics/java/android/graphics/Matrix.java
+++ b/graphics/java/android/graphics/Matrix.java
@@ -37,6 +37,188 @@ public class Matrix {
public static final int MPERSP_1 = 7; //!< use with getValues/setValues
public static final int MPERSP_2 = 8; //!< use with getValues/setValues
+ /** @hide */
+ public static Matrix IDENTITY_MATRIX = new Matrix() {
+ void oops() {
+ throw new IllegalStateException("Matrix can not be modified");
+ }
+
+ @Override
+ public void set(Matrix src) {
+ oops();
+ }
+
+ @Override
+ public void reset() {
+ oops();
+ }
+
+ @Override
+ public void setTranslate(float dx, float dy) {
+ oops();
+ }
+
+ @Override
+ public void setScale(float sx, float sy, float px, float py) {
+ oops();
+ }
+
+ @Override
+ public void setScale(float sx, float sy) {
+ oops();
+ }
+
+ @Override
+ public void setRotate(float degrees, float px, float py) {
+ oops();
+ }
+
+ @Override
+ public void setRotate(float degrees) {
+ oops();
+ }
+
+ @Override
+ public void setSinCos(float sinValue, float cosValue, float px, float py) {
+ oops();
+ }
+
+ @Override
+ public void setSinCos(float sinValue, float cosValue) {
+ oops();
+ }
+
+ @Override
+ public void setSkew(float kx, float ky, float px, float py) {
+ oops();
+ }
+
+ @Override
+ public void setSkew(float kx, float ky) {
+ oops();
+ }
+
+ @Override
+ public boolean setConcat(Matrix a, Matrix b) {
+ oops();
+ return false;
+ }
+
+ @Override
+ public boolean preTranslate(float dx, float dy) {
+ oops();
+ return false;
+ }
+
+ @Override
+ public boolean preScale(float sx, float sy, float px, float py) {
+ oops();
+ return false;
+ }
+
+ @Override
+ public boolean preScale(float sx, float sy) {
+ oops();
+ return false;
+ }
+
+ @Override
+ public boolean preRotate(float degrees, float px, float py) {
+ oops();
+ return false;
+ }
+
+ @Override
+ public boolean preRotate(float degrees) {
+ oops();
+ return false;
+ }
+
+ @Override
+ public boolean preSkew(float kx, float ky, float px, float py) {
+ oops();
+ return false;
+ }
+
+ @Override
+ public boolean preSkew(float kx, float ky) {
+ oops();
+ return false;
+ }
+
+ @Override
+ public boolean preConcat(Matrix other) {
+ oops();
+ return false;
+ }
+
+ @Override
+ public boolean postTranslate(float dx, float dy) {
+ oops();
+ return false;
+ }
+
+ @Override
+ public boolean postScale(float sx, float sy, float px, float py) {
+ oops();
+ return false;
+ }
+
+ @Override
+ public boolean postScale(float sx, float sy) {
+ oops();
+ return false;
+ }
+
+ @Override
+ public boolean postRotate(float degrees, float px, float py) {
+ oops();
+ return false;
+ }
+
+ @Override
+ public boolean postRotate(float degrees) {
+ oops();
+ return false;
+ }
+
+ @Override
+ public boolean postSkew(float kx, float ky, float px, float py) {
+ oops();
+ return false;
+ }
+
+ @Override
+ public boolean postSkew(float kx, float ky) {
+ oops();
+ return false;
+ }
+
+ @Override
+ public boolean postConcat(Matrix other) {
+ oops();
+ return false;
+ }
+
+ @Override
+ public boolean setRectToRect(RectF src, RectF dst, ScaleToFit stf) {
+ oops();
+ return false;
+ }
+
+ @Override
+ public boolean setPolyToPoly(float[] src, int srcIndex, float[] dst, int dstIndex,
+ int pointCount) {
+ oops();
+ return false;
+ }
+
+ @Override
+ public void setValues(float[] values) {
+ oops();
+ }
+ };
+
/**
* @hide
*/
diff --git a/graphics/java/android/graphics/Paint.java b/graphics/java/android/graphics/Paint.java
index 0a23bae..ce42612 100644
--- a/graphics/java/android/graphics/Paint.java
+++ b/graphics/java/android/graphics/Paint.java
@@ -70,16 +70,16 @@ public class Paint {
*/
public int mBidiFlags = BIDI_DEFAULT_LTR;
- private static final Style[] sStyleArray = {
+ static final Style[] sStyleArray = {
Style.FILL, Style.STROKE, Style.FILL_AND_STROKE
};
- private static final Cap[] sCapArray = {
+ static final Cap[] sCapArray = {
Cap.BUTT, Cap.ROUND, Cap.SQUARE
};
- private static final Join[] sJoinArray = {
+ static final Join[] sJoinArray = {
Join.MITER, Join.ROUND, Join.BEVEL
};
- private static final Align[] sAlignArray = {
+ static final Align[] sAlignArray = {
Align.LEFT, Align.CENTER, Align.RIGHT
};
@@ -103,7 +103,17 @@ public class Paint {
public static final int DEV_KERN_TEXT_FLAG = 0x100;
// we use this when we first create a paint
- private static final int DEFAULT_PAINT_FLAGS = DEV_KERN_TEXT_FLAG;
+ static final int DEFAULT_PAINT_FLAGS = DEV_KERN_TEXT_FLAG;
+
+ /**
+ * Option for {@link #setHinting}: disable hinting.
+ */
+ public static final int HINTING_OFF = 0x0;
+
+ /**
+ * Option for {@link #setHinting}: enable hinting.
+ */
+ public static final int HINTING_ON = 0x1;
/**
* Bidi flag to set LTR paragraph direction.
@@ -333,6 +343,10 @@ public class Paint {
public Paint(int flags) {
mNativePaint = native_init();
setFlags(flags | DEFAULT_PAINT_FLAGS);
+ // TODO: Turning off hinting has undesirable side effects, we need to
+ // revisit hinting once we add support for subpixel positioning
+ // setHinting(DisplayMetrics.DENSITY_DEVICE >= DisplayMetrics.DENSITY_TV
+ // ? HINTING_OFF : HINTING_ON);
mCompatScaling = mInvCompatScaling = 1;
}
@@ -345,16 +359,17 @@ public class Paint {
*/
public Paint(Paint paint) {
mNativePaint = native_initWithPaint(paint.mNativePaint);
- mHasCompatScaling = paint.mHasCompatScaling;
- mCompatScaling = paint.mCompatScaling;
- mInvCompatScaling = paint.mInvCompatScaling;
- mBidiFlags = paint.mBidiFlags;
+ setClassVariablesFrom(paint);
}
/** Restores the paint to its default settings. */
public void reset() {
native_reset(mNativePaint);
setFlags(DEFAULT_PAINT_FLAGS);
+ // TODO: Turning off hinting has undesirable side effects, we need to
+ // revisit hinting once we add support for subpixel positioning
+ // setHinting(DisplayMetrics.DENSITY_DEVICE >= DisplayMetrics.DENSITY_TV
+ // ? HINTING_OFF : HINTING_ON);
mHasCompatScaling = false;
mCompatScaling = mInvCompatScaling = 1;
mBidiFlags = BIDI_DEFAULT_LTR;
@@ -369,21 +384,36 @@ public class Paint {
if (this != src) {
// copy over the native settings
native_set(mNativePaint, src.mNativePaint);
- // copy over our java settings
- mColorFilter = src.mColorFilter;
- mMaskFilter = src.mMaskFilter;
- mPathEffect = src.mPathEffect;
- mRasterizer = src.mRasterizer;
- mShader = src.mShader;
- mTypeface = src.mTypeface;
- mXfermode = src.mXfermode;
- mHasCompatScaling = src.mHasCompatScaling;
- mCompatScaling = src.mCompatScaling;
- mInvCompatScaling = src.mInvCompatScaling;
- mBidiFlags = src.mBidiFlags;
+ setClassVariablesFrom(src);
}
}
+ /**
+ * Set all class variables using current values from the given
+ * {@link Paint}.
+ */
+ private void setClassVariablesFrom(Paint paint) {
+ mColorFilter = paint.mColorFilter;
+ mMaskFilter = paint.mMaskFilter;
+ mPathEffect = paint.mPathEffect;
+ mRasterizer = paint.mRasterizer;
+ mShader = paint.mShader;
+ mTypeface = paint.mTypeface;
+ mXfermode = paint.mXfermode;
+
+ mHasCompatScaling = paint.mHasCompatScaling;
+ mCompatScaling = paint.mCompatScaling;
+ mInvCompatScaling = paint.mInvCompatScaling;
+
+ hasShadow = paint.hasShadow;
+ shadowDx = paint.shadowDx;
+ shadowDy = paint.shadowDy;
+ shadowRadius = paint.shadowRadius;
+ shadowColor = paint.shadowColor;
+
+ mBidiFlags = paint.mBidiFlags;
+ }
+
/** @hide */
public void setCompatibilityScaling(float factor) {
if (factor == 1.0) {
@@ -434,6 +464,18 @@ public class Paint {
public native void setFlags(int flags);
/**
+ * Return the paint's hinting mode. Returns either
+ * {@link #HINTING_OFF} or {@link #HINTING_ON}.
+ */
+ public native int getHinting();
+
+ /**
+ * Set the paint's hinting mode. May be either
+ * {@link #HINTING_OFF} or {@link #HINTING_ON}.
+ */
+ public native void setHinting(int mode);
+
+ /**
* Helper for getFlags(), returning true if ANTI_ALIAS_FLAG bit is set
* AntiAliasing smooths out the edges of what is being drawn, but is has
* no impact on the interior of the shape. See setDither() and
@@ -1167,13 +1209,26 @@ public class Paint {
/**
* Return the width of the text.
*
- * @param text The text to measure
+ * @param text The text to measure. Cannot be null.
* @param index The index of the first character to start measuring
* @param count THe number of characters to measure, beginning with start
* @return The width of the text
*/
public float measureText(char[] text, int index, int count) {
- if (!mHasCompatScaling) return native_measureText(text, index, count);
+ if (text == null) {
+ throw new IllegalArgumentException("text cannot be null");
+ }
+ if ((index | count) < 0 || index + count > text.length) {
+ throw new ArrayIndexOutOfBoundsException();
+ }
+
+ if (text.length == 0 || count == 0) {
+ return 0f;
+ }
+ if (!mHasCompatScaling) {
+ return native_measureText(text, index, count);
+ }
+
final float oldSize = getTextSize();
setTextSize(oldSize*mCompatScaling);
float w = native_measureText(text, index, count);
@@ -1186,13 +1241,26 @@ public class Paint {
/**
* Return the width of the text.
*
- * @param text The text to measure
+ * @param text The text to measure. Cannot be null.
* @param start The index of the first character to start measuring
* @param end 1 beyond the index of the last character to measure
* @return The width of the text
*/
public float measureText(String text, int start, int end) {
- if (!mHasCompatScaling) return native_measureText(text, start, end);
+ if (text == null) {
+ throw new IllegalArgumentException("text cannot be null");
+ }
+ if ((start | end | (end - start) | (text.length() - end)) < 0) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ if (text.length() == 0 || start == end) {
+ return 0f;
+ }
+ if (!mHasCompatScaling) {
+ return native_measureText(text, start, end);
+ }
+
final float oldSize = getTextSize();
setTextSize(oldSize*mCompatScaling);
float w = native_measureText(text, start, end);
@@ -1205,10 +1273,18 @@ public class Paint {
/**
* Return the width of the text.
*
- * @param text The text to measure
+ * @param text The text to measure. Cannot be null.
* @return The width of the text
*/
public float measureText(String text) {
+ if (text == null) {
+ throw new IllegalArgumentException("text cannot be null");
+ }
+
+ if (text.length() == 0) {
+ return 0f;
+ }
+
if (!mHasCompatScaling) return native_measureText(text);
final float oldSize = getTextSize();
setTextSize(oldSize*mCompatScaling);
@@ -1228,6 +1304,16 @@ public class Paint {
* @return The width of the text
*/
public float measureText(CharSequence text, int start, int end) {
+ if (text == null) {
+ throw new IllegalArgumentException("text cannot be null");
+ }
+ if ((start | end | (end - start) | (text.length() - end)) < 0) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ if (text.length() == 0 || start == end) {
+ return 0f;
+ }
if (text instanceof String) {
return measureText((String)text, start, end);
}
@@ -1251,7 +1337,7 @@ public class Paint {
* Return the number of chars that were measured, and if measuredWidth is
* not null, return in it the actual width measured.
*
- * @param text The text to measure
+ * @param text The text to measure. Cannot be null.
* @param index The offset into text to begin measuring at
* @param count The number of maximum number of entries to measure. If count
* is negative, then the characters are measured in reverse order.
@@ -1263,9 +1349,20 @@ public class Paint {
*/
public int breakText(char[] text, int index, int count,
float maxWidth, float[] measuredWidth) {
+ if (text == null) {
+ throw new IllegalArgumentException("text cannot be null");
+ }
+ if (index < 0 || text.length - index < Math.abs(count)) {
+ throw new ArrayIndexOutOfBoundsException();
+ }
+
+ if (text.length == 0 || count == 0) {
+ return 0;
+ }
if (!mHasCompatScaling) {
return native_breakText(text, index, count, maxWidth, measuredWidth);
}
+
final float oldSize = getTextSize();
setTextSize(oldSize*mCompatScaling);
int res = native_breakText(text, index, count, maxWidth*mCompatScaling,
@@ -1283,7 +1380,7 @@ public class Paint {
* Return the number of chars that were measured, and if measuredWidth is
* not null, return in it the actual width measured.
*
- * @param text The text to measure
+ * @param text The text to measure. Cannot be null.
* @param start The offset into text to begin measuring at
* @param end The end of the text slice to measure.
* @param measureForwards If true, measure forwards, starting at start.
@@ -1297,6 +1394,16 @@ public class Paint {
public int breakText(CharSequence text, int start, int end,
boolean measureForwards,
float maxWidth, float[] measuredWidth) {
+ if (text == null) {
+ throw new IllegalArgumentException("text cannot be null");
+ }
+ if ((start | end | (end - start) | (text.length() - end)) < 0) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ if (text.length() == 0 || start == end) {
+ return 0;
+ }
if (start == 0 && text instanceof String && end == text.length()) {
return breakText((String) text, measureForwards, maxWidth,
measuredWidth);
@@ -1322,7 +1429,7 @@ public class Paint {
* Return the number of chars that were measured, and if measuredWidth is
* not null, return in it the actual width measured.
*
- * @param text The text to measure
+ * @param text The text to measure. Cannot be null.
* @param measureForwards If true, measure forwards, starting with the
* first character in the string. Otherwise,
* measure backwards, starting with the
@@ -1335,9 +1442,17 @@ public class Paint {
*/
public int breakText(String text, boolean measureForwards,
float maxWidth, float[] measuredWidth) {
+ if (text == null) {
+ throw new IllegalArgumentException("text cannot be null");
+ }
+
+ if (text.length() == 0) {
+ return 0;
+ }
if (!mHasCompatScaling) {
return native_breakText(text, measureForwards, maxWidth, measuredWidth);
}
+
final float oldSize = getTextSize();
setTextSize(oldSize*mCompatScaling);
int res = native_breakText(text, measureForwards, maxWidth*mCompatScaling,
@@ -1353,7 +1468,7 @@ public class Paint {
/**
* Return the advance widths for the characters in the string.
*
- * @param text The text to measure
+ * @param text The text to measure. Cannot be null.
* @param index The index of the first char to to measure
* @param count The number of chars starting with index to measure
* @param widths array to receive the advance widths of the characters.
@@ -1362,14 +1477,21 @@ public class Paint {
*/
public int getTextWidths(char[] text, int index, int count,
float[] widths) {
+ if (text == null) {
+ throw new IllegalArgumentException("text cannot be null");
+ }
if ((index | count) < 0 || index + count > text.length
|| count > widths.length) {
throw new ArrayIndexOutOfBoundsException();
}
-
+
+ if (text.length == 0 || count == 0) {
+ return 0;
+ }
if (!mHasCompatScaling) {
return native_getTextWidths(mNativePaint, text, index, count, widths);
}
+
final float oldSize = getTextSize();
setTextSize(oldSize*mCompatScaling);
int res = native_getTextWidths(mNativePaint, text, index, count, widths);
@@ -1383,7 +1505,7 @@ public class Paint {
/**
* Return the advance widths for the characters in the string.
*
- * @param text The text to measure
+ * @param text The text to measure. Cannot be null.
* @param start The index of the first char to to measure
* @param end The end of the text slice to measure
* @param widths array to receive the advance widths of the characters.
@@ -1392,6 +1514,19 @@ public class Paint {
*/
public int getTextWidths(CharSequence text, int start, int end,
float[] widths) {
+ if (text == null) {
+ throw new IllegalArgumentException("text cannot be null");
+ }
+ if ((start | end | (end - start) | (text.length() - end)) < 0) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (end - start > widths.length) {
+ throw new ArrayIndexOutOfBoundsException();
+ }
+
+ if (text.length() == 0 || start == end) {
+ return 0;
+ }
if (text instanceof String) {
return getTextWidths((String) text, start, end, widths);
}
@@ -1414,7 +1549,7 @@ public class Paint {
/**
* Return the advance widths for the characters in the string.
*
- * @param text The text to measure
+ * @param text The text to measure. Cannot be null.
* @param start The index of the first char to to measure
* @param end The end of the text slice to measure
* @param widths array to receive the advance widths of the characters.
@@ -1422,6 +1557,9 @@ public class Paint {
* @return the number of unichars in the specified text.
*/
public int getTextWidths(String text, int start, int end, float[] widths) {
+ if (text == null) {
+ throw new IllegalArgumentException("text cannot be null");
+ }
if ((start | end | (end - start) | (text.length() - end)) < 0) {
throw new IndexOutOfBoundsException();
}
@@ -1429,9 +1567,13 @@ public class Paint {
throw new ArrayIndexOutOfBoundsException();
}
+ if (text.length() == 0 || start == end) {
+ return 0;
+ }
if (!mHasCompatScaling) {
return native_getTextWidths(mNativePaint, text, start, end, widths);
}
+
final float oldSize = getTextSize();
setTextSize(oldSize*mCompatScaling);
int res = native_getTextWidths(mNativePaint, text, start, end, widths);
@@ -1455,6 +1597,46 @@ public class Paint {
}
/**
+ * Return the glyph Ids for the characters in the string.
+ *
+ * @param text The text to measure
+ * @param start The index of the first char to to measure
+ * @param end The end of the text slice to measure
+ * @param contextStart the index of the first character to use for shaping context,
+ * must be <= start
+ * @param contextEnd the index past the last character to use for shaping context,
+ * must be >= end
+ * @param flags the flags to control the advances, either {@link #DIRECTION_LTR}
+ * or {@link #DIRECTION_RTL}
+ * @param glyphs array to receive the glyph Ids of the characters.
+ * Must be at least a large as the text.
+ * @return the number of glyphs in the returned array
+ *
+ * @hide
+ *
+ * Used only for BiDi / RTL Tests
+ */
+ public int getTextGlyphs(String text, int start, int end, int contextStart, int contextEnd,
+ int flags, char[] glyphs) {
+ if (text == null) {
+ throw new IllegalArgumentException("text cannot be null");
+ }
+ if (flags != DIRECTION_LTR && flags != DIRECTION_RTL) {
+ throw new IllegalArgumentException("unknown flags value: " + flags);
+ }
+ if ((start | end | contextStart | contextEnd | (end - start)
+ | (start - contextStart) | (contextEnd - end) | (text.length() - end)
+ | (text.length() - contextEnd)) < 0) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (end - start > glyphs.length) {
+ throw new ArrayIndexOutOfBoundsException();
+ }
+ return native_getTextGlyphs(mNativePaint, text, start, end, contextStart, contextEnd,
+ flags, glyphs);
+ }
+
+ /**
* Convenience overload that takes a char array instead of a
* String.
*
@@ -1464,28 +1646,48 @@ public class Paint {
public float getTextRunAdvances(char[] chars, int index, int count,
int contextIndex, int contextCount, int flags, float[] advances,
int advancesIndex) {
+ return getTextRunAdvances(chars, index, count, contextIndex, contextCount, flags,
+ advances, advancesIndex, 0 /* use Harfbuzz*/);
+ }
+ /**
+ * Convenience overload that takes a char array instead of a
+ * String.
+ *
+ * @see #getTextRunAdvances(String, int, int, int, int, int, float[], int, int)
+ * @hide
+ */
+ public float getTextRunAdvances(char[] chars, int index, int count,
+ int contextIndex, int contextCount, int flags, float[] advances,
+ int advancesIndex, int reserved) {
+
+ if (chars == null) {
+ throw new IllegalArgumentException("text cannot be null");
+ }
+ if (flags != DIRECTION_LTR && flags != DIRECTION_RTL) {
+ throw new IllegalArgumentException("unknown flags value: " + flags);
+ }
if ((index | count | contextIndex | contextCount | advancesIndex
- | (index - contextIndex)
+ | (index - contextIndex) | (contextCount - count)
| ((contextIndex + contextCount) - (index + count))
| (chars.length - (contextIndex + contextCount))
| (advances == null ? 0 :
(advances.length - (advancesIndex + count)))) < 0) {
throw new IndexOutOfBoundsException();
}
- if (flags != DIRECTION_LTR && flags != DIRECTION_RTL) {
- throw new IllegalArgumentException("unknown flags value: " + flags);
- }
+ if (chars.length == 0 || count == 0){
+ return 0f;
+ }
if (!mHasCompatScaling) {
return native_getTextRunAdvances(mNativePaint, chars, index, count,
- contextIndex, contextCount, flags, advances, advancesIndex);
+ contextIndex, contextCount, flags, advances, advancesIndex, reserved);
}
final float oldSize = getTextSize();
setTextSize(oldSize * mCompatScaling);
float res = native_getTextRunAdvances(mNativePaint, chars, index, count,
- contextIndex, contextCount, flags, advances, advancesIndex);
+ contextIndex, contextCount, flags, advances, advancesIndex, reserved);
setTextSize(oldSize);
if (advances != null) {
@@ -1506,27 +1708,55 @@ public class Paint {
public float getTextRunAdvances(CharSequence text, int start, int end,
int contextStart, int contextEnd, int flags, float[] advances,
int advancesIndex) {
+ return getTextRunAdvances(text, start, end, contextStart, contextEnd, flags,
+ advances, advancesIndex, 0 /* use Harfbuzz */);
+ }
+
+ /**
+ * Convenience overload that takes a CharSequence instead of a
+ * String.
+ *
+ * @see #getTextRunAdvances(String, int, int, int, int, int, float[], int)
+ * @hide
+ */
+ public float getTextRunAdvances(CharSequence text, int start, int end,
+ int contextStart, int contextEnd, int flags, float[] advances,
+ int advancesIndex, int reserved) {
+
+ if (text == null) {
+ throw new IllegalArgumentException("text cannot be null");
+ }
+ if ((start | end | contextStart | contextEnd | advancesIndex | (end - start)
+ | (start - contextStart) | (contextEnd - end)
+ | (text.length() - contextEnd)
+ | (advances == null ? 0 :
+ (advances.length - advancesIndex - (end - start)))) < 0) {
+ throw new IndexOutOfBoundsException();
+ }
if (text instanceof String) {
return getTextRunAdvances((String) text, start, end,
- contextStart, contextEnd, flags, advances, advancesIndex);
+ contextStart, contextEnd, flags, advances, advancesIndex, reserved);
}
if (text instanceof SpannedString ||
text instanceof SpannableString) {
return getTextRunAdvances(text.toString(), start, end,
- contextStart, contextEnd, flags, advances, advancesIndex);
+ contextStart, contextEnd, flags, advances, advancesIndex, reserved);
}
if (text instanceof GraphicsOperations) {
return ((GraphicsOperations) text).getTextRunAdvances(start, end,
contextStart, contextEnd, flags, advances, advancesIndex, this);
}
+ if (text.length() == 0 || end == start) {
+ return 0f;
+ }
int contextLen = contextEnd - contextStart;
int len = end - start;
char[] buf = TemporaryBuffer.obtain(contextLen);
- TextUtils.getChars(text, start, end, buf, 0);
+ TextUtils.getChars(text, contextStart, contextEnd, buf, 0);
float result = getTextRunAdvances(buf, start - contextStart, len,
- 0, contextLen, flags, advances, advancesIndex);
+ 0, contextLen, flags, advances, advancesIndex, reserved);
TemporaryBuffer.recycle(buf);
return result;
}
@@ -1556,7 +1786,7 @@ public class Paint {
* These bounds typically reflect changes in bidi level or font
* metrics across which shaping does not occur.
*
- * @param text the text to measure
+ * @param text the text to measure. Cannot be null.
* @param start the index of the first character to measure
* @param end the index past the last character to measure
* @param contextStart the index of the first character to use for shaping context,
@@ -1575,7 +1805,62 @@ public class Paint {
*/
public float getTextRunAdvances(String text, int start, int end, int contextStart,
int contextEnd, int flags, float[] advances, int advancesIndex) {
+ return getTextRunAdvances(text, start, end, contextStart, contextEnd, flags,
+ advances, advancesIndex, 0 /* use Harfbuzz*/);
+ }
+
+ /**
+ * Returns the total advance width for the characters in the run
+ * between start and end, and if advances is not null, the advance
+ * assigned to each of these characters (java chars).
+ *
+ * <p>The trailing surrogate in a valid surrogate pair is assigned
+ * an advance of 0. Thus the number of returned advances is
+ * always equal to count, not to the number of unicode codepoints
+ * represented by the run.
+ *
+ * <p>In the case of conjuncts or combining marks, the total
+ * advance is assigned to the first logical character, and the
+ * following characters are assigned an advance of 0.
+ *
+ * <p>This generates the sum of the advances of glyphs for
+ * characters in a reordered cluster as the width of the first
+ * logical character in the cluster, and 0 for the widths of all
+ * other characters in the cluster. In effect, such clusters are
+ * treated like conjuncts.
+ *
+ * <p>The shaping bounds limit the amount of context available
+ * outside start and end that can be used for shaping analysis.
+ * These bounds typically reflect changes in bidi level or font
+ * metrics across which shaping does not occur.
+ *
+ * @param text the text to measure. Cannot be null.
+ * @param start the index of the first character to measure
+ * @param end the index past the last character to measure
+ * @param contextStart the index of the first character to use for shaping context,
+ * must be <= start
+ * @param contextEnd the index past the last character to use for shaping context,
+ * must be >= end
+ * @param flags the flags to control the advances, either {@link #DIRECTION_LTR}
+ * or {@link #DIRECTION_RTL}
+ * @param advances array to receive the advances, must have room for all advances,
+ * can be null if only total advance is needed
+ * @param advancesIndex the position in advances at which to put the
+ * advance corresponding to the character at start
+ * @param reserved int reserved value
+ * @return the total advance
+ *
+ * @hide
+ */
+ public float getTextRunAdvances(String text, int start, int end, int contextStart,
+ int contextEnd, int flags, float[] advances, int advancesIndex, int reserved) {
+ if (text == null) {
+ throw new IllegalArgumentException("text cannot be null");
+ }
+ if (flags != DIRECTION_LTR && flags != DIRECTION_RTL) {
+ throw new IllegalArgumentException("unknown flags value: " + flags);
+ }
if ((start | end | contextStart | contextEnd | advancesIndex | (end - start)
| (start - contextStart) | (contextEnd - end)
| (text.length() - contextEnd)
@@ -1583,19 +1868,20 @@ public class Paint {
(advances.length - advancesIndex - (end - start)))) < 0) {
throw new IndexOutOfBoundsException();
}
- if (flags != DIRECTION_LTR && flags != DIRECTION_RTL) {
- throw new IllegalArgumentException("unknown flags value: " + flags);
+
+ if (text.length() == 0 || start == end) {
+ return 0f;
}
if (!mHasCompatScaling) {
return native_getTextRunAdvances(mNativePaint, text, start, end,
- contextStart, contextEnd, flags, advances, advancesIndex);
+ contextStart, contextEnd, flags, advances, advancesIndex, reserved);
}
final float oldSize = getTextSize();
setTextSize(oldSize * mCompatScaling);
float totalAdvance = native_getTextRunAdvances(mNativePaint, text, start, end,
- contextStart, contextEnd, flags, advances, advancesIndex);
+ contextStart, contextEnd, flags, advances, advancesIndex, reserved);
setTextSize(oldSize);
if (advances != null) {
@@ -1818,7 +2104,11 @@ public class Paint {
@Override
protected void finalize() throws Throwable {
- finalizer(mNativePaint);
+ try {
+ finalizer(mNativePaint);
+ } finally {
+ super.finalize();
+ }
}
private static native int native_init();
@@ -1859,12 +2149,16 @@ public class Paint {
private static native int native_getTextWidths(int native_object,
String text, int start, int end, float[] widths);
+ private static native int native_getTextGlyphs(int native_object,
+ String text, int start, int end, int contextStart, int contextEnd,
+ int flags, char[] glyphs);
+
private static native float native_getTextRunAdvances(int native_object,
char[] text, int index, int count, int contextIndex, int contextCount,
- int flags, float[] advances, int advancesIndex);
+ int flags, float[] advances, int advancesIndex, int reserved);
private static native float native_getTextRunAdvances(int native_object,
String text, int start, int end, int contextStart, int contextEnd,
- int flags, float[] advances, int advancesIndex);
+ int flags, float[] advances, int advancesIndex, int reserved);
private native int native_getTextRunCursor(int native_object, char[] text,
int contextStart, int contextLength, int flags, int offset, int cursorOpt);
diff --git a/graphics/java/android/graphics/Path.java b/graphics/java/android/graphics/Path.java
index 1324431..b4f1e84 100644
--- a/graphics/java/android/graphics/Path.java
+++ b/graphics/java/android/graphics/Path.java
@@ -40,6 +40,7 @@ public class Path {
*/
public Region rects;
private boolean mDetectSimplePaths;
+ private Direction mLastDirection = null;
/**
* Create an empty path
@@ -70,6 +71,7 @@ public class Path {
public void reset() {
isSimplePath = true;
if (mDetectSimplePaths) {
+ mLastDirection = null;
if (rects != null) rects.setEmpty();
}
native_reset(mNativePath);
@@ -82,6 +84,7 @@ public class Path {
public void rewind() {
isSimplePath = true;
if (mDetectSimplePaths) {
+ mLastDirection = null;
if (rects != null) rects.setEmpty();
}
native_rewind(mNativePath);
@@ -112,7 +115,7 @@ public class Path {
}
// these must be in the same order as their native values
- private static final FillType[] sFillTypeArray = {
+ static final FillType[] sFillTypeArray = {
FillType.WINDING,
FillType.EVEN_ODD,
FillType.INVERSE_WINDING,
@@ -378,6 +381,20 @@ public class Path {
final int nativeInt;
}
+ private void detectSimplePath(float left, float top, float right, float bottom, Direction dir) {
+ if (mDetectSimplePaths) {
+ if (mLastDirection == null) {
+ mLastDirection = dir;
+ }
+ if (mLastDirection != dir) {
+ isSimplePath = false;
+ } else {
+ if (rects == null) rects = new Region();
+ rects.op((int) left, (int) top, (int) right, (int) bottom, Region.Op.UNION);
+ }
+ }
+ }
+
/**
* Add a closed rectangle contour to the path
*
@@ -388,11 +405,7 @@ public class Path {
if (rect == null) {
throw new NullPointerException("need rect parameter");
}
- if (mDetectSimplePaths) {
- if (rects == null) rects = new Region();
- rects.op((int) rect.left, (int) rect.top, (int) rect.right, (int) rect.bottom,
- Region.Op.UNION);
- }
+ detectSimplePath(rect.left, rect.top, rect.right, rect.bottom, dir);
native_addRect(mNativePath, rect, dir.nativeInt);
}
@@ -406,10 +419,7 @@ public class Path {
* @param dir The direction to wind the rectangle's contour
*/
public void addRect(float left, float top, float right, float bottom, Direction dir) {
- if (mDetectSimplePaths) {
- if (rects == null) rects = new Region();
- rects.op((int) left, (int) top, (int) right, (int) bottom, Region.Op.UNION);
- }
+ detectSimplePath(left, top, right, bottom, dir);
native_addRect(mNativePath, left, top, right, bottom, dir.nativeInt);
}
diff --git a/graphics/java/android/graphics/RectF.java b/graphics/java/android/graphics/RectF.java
index 2b3aa33..00e9609 100644
--- a/graphics/java/android/graphics/RectF.java
+++ b/graphics/java/android/graphics/RectF.java
@@ -16,6 +16,8 @@
package android.graphics;
+import java.io.PrintWriter;
+
import android.os.Parcel;
import android.os.Parcelable;
import android.util.FloatMath;
@@ -81,8 +83,37 @@ public class RectF implements Parcelable {
return "RectF(" + left + ", " + top + ", "
+ right + ", " + bottom + ")";
}
+
+ /**
+ * Return a string representation of the rectangle in a compact form.
+ */
+ public String toShortString() {
+ return toShortString(new StringBuilder(32));
+ }
/**
+ * Return a string representation of the rectangle in a compact form.
+ * @hide
+ */
+ public String toShortString(StringBuilder sb) {
+ sb.setLength(0);
+ sb.append('['); sb.append(left); sb.append(',');
+ sb.append(top); sb.append("]["); sb.append(right);
+ sb.append(','); sb.append(bottom); sb.append(']');
+ return sb.toString();
+ }
+
+ /**
+ * Print short representation to given writer.
+ * @hide
+ */
+ public void printShortString(PrintWriter pw) {
+ pw.print('['); pw.print(left); pw.print(',');
+ pw.print(top); pw.print("]["); pw.print(right);
+ pw.print(','); pw.print(bottom); pw.print(']');
+ }
+
+ /**
* Returns true if the rectangle is empty (left >= right or top >= bottom)
*/
public final boolean isEmpty() {
diff --git a/graphics/java/android/graphics/SurfaceTexture.java b/graphics/java/android/graphics/SurfaceTexture.java
index 970b207..f3b62ec 100644
--- a/graphics/java/android/graphics/SurfaceTexture.java
+++ b/graphics/java/android/graphics/SurfaceTexture.java
@@ -34,8 +34,9 @@ import android.os.Message;
* the stream to be skipped.
*
* <p>When sampling from the texture one should first transform the texture coordinates using the
- * matrix queried via {@link #getTransformMatrix}. The transform matrix may change each time {@link
- * #updateTexImage} is called, so it should be re-queried each time the texture image is updated.
+ * matrix queried via {@link #getTransformMatrix(float[])}. The transform matrix may change each
+ * time {@link #updateTexImage} is called, so it should be re-queried each time the texture image
+ * is updated.
* This matrix transforms traditional 2D OpenGL ES texture coordinate column vectors of the form (s,
* t, 0, 1) where s and t are on the inclusive interval [0, 1] to the proper sampling location in
* the streamed texture. This transform compensates for any properties of the image stream source
@@ -63,7 +64,9 @@ public class SurfaceTexture {
private EventHandler mEventHandler;
private OnFrameAvailableListener mOnFrameAvailableListener;
- @SuppressWarnings("unused")
+ /**
+ * This field is used by native code, do not access or modify.
+ */
private int mSurfaceTexture;
/**
@@ -90,6 +93,21 @@ public class SurfaceTexture {
* @param texName the OpenGL texture object name (e.g. generated via glGenTextures)
*/
public SurfaceTexture(int texName) {
+ this(texName, false);
+ }
+
+ /**
+ * Construct a new SurfaceTexture to stream images to a given OpenGL texture.
+ *
+ * @param texName the OpenGL texture object name (e.g. generated via glGenTextures)
+ * @param allowSynchronousMode whether the SurfaceTexture can run in the synchronous mode.
+ * When the image stream comes from OpenGL, SurfaceTexture may run in the synchronous
+ * mode where the producer side may be blocked to avoid skipping frames. To avoid the
+ * thread block, set allowSynchronousMode to false.
+ *
+ * @hide
+ */
+ public SurfaceTexture(int texName, boolean allowSynchronousMode) {
Looper looper;
if ((looper = Looper.myLooper()) != null) {
mEventHandler = new EventHandler(looper);
@@ -98,7 +116,7 @@ public class SurfaceTexture {
} else {
mEventHandler = null;
}
- nativeInit(texName, new WeakReference<SurfaceTexture>(this));
+ nativeInit(texName, new WeakReference<SurfaceTexture>(this), allowSynchronousMode);
}
/**
@@ -112,6 +130,16 @@ public class SurfaceTexture {
}
/**
+ * Set the size of buffers returned by requestBuffers when a width and height
+ * of zero is requested.
+ *
+ * @hide Pending approval by API council.
+ */
+ public void setDefaultBufferSize(int width, int height) {
+ nativeSetDefaultBufferSize(width, height);
+ }
+
+ /**
* Update the texture image to the most recent frame from the image stream. This may only be
* called while the OpenGL ES context that owns the texture is bound to the thread. It will
* implicitly bind its texture to the GL_TEXTURE_EXTERNAL_OES texture target.
@@ -144,6 +172,42 @@ public class SurfaceTexture {
nativeGetTransformMatrix(mtx);
}
+ /**
+ * Retrieve the timestamp associated with the texture image set by the most recent call to
+ * updateTexImage.
+ *
+ * This timestamp is in nanoseconds, and is normally monotonically increasing. The timestamp
+ * should be unaffected by time-of-day adjustments, and for a camera should be strictly
+ * monotonic but for a MediaPlayer may be reset when the position is set. The
+ * specific meaning and zero point of the timestamp depends on the source providing images to
+ * the SurfaceTexture. Unless otherwise specified by the image source, timestamps cannot
+ * generally be compared across SurfaceTexture instances, or across multiple program
+ * invocations. It is mostly useful for determining time offsets between subsequent frames.
+ */
+
+ public long getTimestamp() {
+ return nativeGetTimestamp();
+ }
+
+ /**
+ * release() frees all the buffers and puts the SurfaceTexture into the
+ * 'abandoned' state. Once put in this state the SurfaceTexture can never
+ * leave it. When in the 'abandoned' state, all methods of the
+ * ISurfaceTexture interface will fail with the NO_INIT error.
+ *
+ * Note that while calling this method causes all the buffers to be freed
+ * from the perspective of the the SurfaceTexture, if there are additional
+ * references on the buffers (e.g. if a buffer is referenced by a client or
+ * by OpenGL ES as a texture) then those buffer will remain allocated.
+ *
+ * Always call this method when you are done with SurfaceTexture. Failing
+ * to do so may delay resource deallocation for a significant amount of
+ * time.
+ */
+ public void release() {
+ nativeRelease();
+ }
+
protected void finalize() throws Throwable {
try {
nativeFinalize();
@@ -162,10 +226,13 @@ public class SurfaceTexture {
if (mOnFrameAvailableListener != null) {
mOnFrameAvailableListener.onFrameAvailable(SurfaceTexture.this);
}
- return;
}
}
+ /**
+ * This method is invoked from native code only.
+ */
+ @SuppressWarnings({"UnusedDeclaration"})
private static void postEventFromNative(Object selfRef) {
WeakReference weakSelf = (WeakReference)selfRef;
SurfaceTexture st = (SurfaceTexture)weakSelf.get();
@@ -179,10 +246,14 @@ public class SurfaceTexture {
}
}
- private native void nativeInit(int texName, Object weakSelf);
+ private native void nativeInit(int texName, Object weakSelf, boolean allowSynchronousMode);
private native void nativeFinalize();
private native void nativeGetTransformMatrix(float[] mtx);
+ private native long nativeGetTimestamp();
+ private native void nativeSetDefaultBufferSize(int width, int height);
private native void nativeUpdateTexImage();
+ private native int nativeGetQueuedCount();
+ private native void nativeRelease();
/*
* We use a class initializer to allow the native code to cache some
diff --git a/graphics/java/android/graphics/Typeface.java b/graphics/java/android/graphics/Typeface.java
index bc92d3a..ed6fa08 100644
--- a/graphics/java/android/graphics/Typeface.java
+++ b/graphics/java/android/graphics/Typeface.java
@@ -43,7 +43,7 @@ public class Typeface {
/** The NORMAL style of the default monospace typeface. */
public static final Typeface MONOSPACE;
- private static Typeface[] sDefaults;
+ /* package */ static Typeface[] sDefaults;
/* package */ int native_instance;
diff --git a/graphics/java/android/graphics/drawable/AnimatedRotateDrawable.java b/graphics/java/android/graphics/drawable/AnimatedRotateDrawable.java
index 94a8488..34f9070 100644
--- a/graphics/java/android/graphics/drawable/AnimatedRotateDrawable.java
+++ b/graphics/java/android/graphics/drawable/AnimatedRotateDrawable.java
@@ -55,7 +55,7 @@ public class AnimatedRotateDrawable extends Drawable implements Drawable.Callbac
private void init() {
final AnimatedRotateState state = mState;
- mIncrement = 360.0f / (float) state.mFramesCount;
+ mIncrement = 360.0f / state.mFramesCount;
final Drawable drawable = state.mDrawable;
if (drawable != null) {
drawable.setFilterBitmap(true);
@@ -65,6 +65,7 @@ public class AnimatedRotateDrawable extends Drawable implements Drawable.Callbac
}
}
+ @Override
public void draw(Canvas canvas) {
int saveCount = canvas.save();
@@ -78,7 +79,7 @@ public class AnimatedRotateDrawable extends Drawable implements Drawable.Callbac
float px = st.mPivotXRel ? (w * st.mPivotX) : st.mPivotX;
float py = st.mPivotYRel ? (h * st.mPivotY) : st.mPivotY;
- canvas.rotate(mCurrentDegrees, px, py);
+ canvas.rotate(mCurrentDegrees, px + bounds.left, py + bounds.top);
drawable.draw(canvas);
@@ -146,14 +147,17 @@ public class AnimatedRotateDrawable extends Drawable implements Drawable.Callbac
| mState.mDrawable.getChangingConfigurations();
}
+ @Override
public void setAlpha(int alpha) {
mState.mDrawable.setAlpha(alpha);
}
+ @Override
public void setColorFilter(ColorFilter cf) {
mState.mDrawable.setColorFilter(cf);
}
+ @Override
public int getOpacity() {
return mState.mDrawable.getOpacity();
}
@@ -228,10 +232,10 @@ public class AnimatedRotateDrawable extends Drawable implements Drawable.Callbac
tv = a.peekValue(R.styleable.AnimatedRotateDrawable_pivotY);
final boolean pivotYRel = tv.type == TypedValue.TYPE_FRACTION;
final float pivotY = pivotYRel ? tv.getFraction(1.0f, 1.0f) : tv.getFloat();
-
- final int framesCount = a.getInt(R.styleable.AnimatedRotateDrawable_framesCount, 12);
- final int frameDuration = a.getInt(R.styleable.AnimatedRotateDrawable_frameDuration, 150);
-
+
+ setFramesCount(a.getInt(R.styleable.AnimatedRotateDrawable_framesCount, 12));
+ setFramesDuration(a.getInt(R.styleable.AnimatedRotateDrawable_frameDuration, 150));
+
final int res = a.getResourceId(R.styleable.AnimatedRotateDrawable_drawable, 0);
Drawable drawable = null;
if (res > 0) {
@@ -265,8 +269,6 @@ public class AnimatedRotateDrawable extends Drawable implements Drawable.Callbac
rotateState.mPivotX = pivotX;
rotateState.mPivotYRel = pivotYRel;
rotateState.mPivotY = pivotY;
- rotateState.mFramesCount = framesCount;
- rotateState.mFrameDuration = frameDuration;
init();
@@ -275,6 +277,15 @@ public class AnimatedRotateDrawable extends Drawable implements Drawable.Callbac
}
}
+ public void setFramesCount(int framesCount) {
+ mState.mFramesCount = framesCount;
+ mIncrement = 360.0f / mState.mFramesCount;
+ }
+
+ public void setFramesDuration(int framesDuration) {
+ mState.mFrameDuration = framesDuration;
+ }
+
@Override
public Drawable mutate() {
if (!mMutated && super.mutate() == this) {
diff --git a/graphics/java/android/graphics/drawable/AnimationDrawable.java b/graphics/java/android/graphics/drawable/AnimationDrawable.java
index e275ba8..7efdc6c 100644
--- a/graphics/java/android/graphics/drawable/AnimationDrawable.java
+++ b/graphics/java/android/graphics/drawable/AnimationDrawable.java
@@ -33,7 +33,7 @@ import android.util.AttributeSet;
* <p>
* The simplest way to create a frame-by-frame animation is to define the animation in an XML
* file, placed in the res/drawable/ folder, and set it as the background to a View object. Then, call
- * {@link #run()} to start the animation.
+ * {@link #start()} to run the animation.
* <p>
* An AnimationDrawable defined in XML consists of a single <code>&lt;animation-list></code> element,
* and a series of nested <code>&lt;item></code> tags. Each item defines a frame of the animation.
@@ -62,7 +62,7 @@ import android.util.AttributeSet;
* AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
*
* // Start the animation (looped playback by default).
- * frameAnimation.start()
+ * frameAnimation.start();
* </pre>
* <p>For more information, see the guide to <a
* href="{@docRoot}guide/topics/resources/animation-resource.html">Animation Resources</a>.</p>
@@ -192,6 +192,9 @@ public class AnimationDrawable extends DrawableContainer implements Runnable, An
*/
public void addFrame(Drawable frame, int duration) {
mAnimationState.addFrame(frame, duration);
+ if (mCurFrame < 0) {
+ setFrame(0, true, false);
+ }
}
private void nextFrame(boolean unschedule) {
diff --git a/graphics/java/android/graphics/drawable/BitmapDrawable.java b/graphics/java/android/graphics/drawable/BitmapDrawable.java
index 6e62ab3..87421b1 100644
--- a/graphics/java/android/graphics/drawable/BitmapDrawable.java
+++ b/graphics/java/android/graphics/drawable/BitmapDrawable.java
@@ -20,17 +20,16 @@ import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
+import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.Shader;
-import android.graphics.BitmapShader;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.Gravity;
-
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -67,7 +66,6 @@ public class BitmapDrawable extends Drawable {
private final Rect mDstRect = new Rect(); // Gravity.apply() sets this
private boolean mApplyGravity;
- private boolean mRebuildShader;
private boolean mMutated;
// These are scaled to match the target density.
@@ -88,6 +86,7 @@ public class BitmapDrawable extends Drawable {
* Create an empty drawable, setting initial target density based on
* the display metrics of the resources.
*/
+ @SuppressWarnings({"UnusedParameters"})
public BitmapDrawable(Resources res) {
mBitmapState = new BitmapState((Bitmap) null);
mBitmapState.mTargetDensity = mTargetDensity;
@@ -128,6 +127,7 @@ public class BitmapDrawable extends Drawable {
/**
* Create a drawable by opening a given file path and decoding the bitmap.
*/
+ @SuppressWarnings({"UnusedParameters"})
public BitmapDrawable(Resources res, String filepath) {
this(new BitmapState(BitmapFactory.decodeFile(filepath)), null);
mBitmapState.mTargetDensity = mTargetDensity;
@@ -152,6 +152,7 @@ public class BitmapDrawable extends Drawable {
/**
* Create a drawable by decoding a bitmap from the given input stream.
*/
+ @SuppressWarnings({"UnusedParameters"})
public BitmapDrawable(Resources res, java.io.InputStream is) {
this(new BitmapState(BitmapFactory.decodeStream(is)), null);
mBitmapState.mTargetDensity = mTargetDensity;
@@ -160,10 +161,16 @@ public class BitmapDrawable extends Drawable {
}
}
+ /**
+ * Returns the paint used to render this drawable.
+ */
public final Paint getPaint() {
return mBitmapState.mPaint;
}
-
+
+ /**
+ * Returns the bitmap used by this drawable to render. May be null.
+ */
public final Bitmap getBitmap() {
return mBitmap;
}
@@ -249,6 +256,12 @@ public class BitmapDrawable extends Drawable {
}
}
+ /**
+ * Enables or disables anti-aliasing for this drawable. Anti-aliasing affects
+ * the edges of the bitmap only so it applies only when the drawable is rotated.
+ *
+ * @param aa True if the bitmap should be anti-aliased, false otherwise.
+ */
public void setAntiAlias(boolean aa) {
mBitmapState.mPaint.setAntiAlias(aa);
invalidateSelf();
@@ -266,29 +279,74 @@ public class BitmapDrawable extends Drawable {
invalidateSelf();
}
+ /**
+ * Indicates the repeat behavior of this drawable on the X axis.
+ *
+ * @return {@link Shader.TileMode#CLAMP} if the bitmap does not repeat,
+ * {@link Shader.TileMode#REPEAT} or {@link Shader.TileMode#MIRROR} otherwise.
+ */
public Shader.TileMode getTileModeX() {
return mBitmapState.mTileModeX;
}
+ /**
+ * Indicates the repeat behavior of this drawable on the Y axis.
+ *
+ * @return {@link Shader.TileMode#CLAMP} if the bitmap does not repeat,
+ * {@link Shader.TileMode#REPEAT} or {@link Shader.TileMode#MIRROR} otherwise.
+ */
public Shader.TileMode getTileModeY() {
return mBitmapState.mTileModeY;
}
+ /**
+ * Sets the repeat behavior of this drawable on the X axis. By default, the drawable
+ * does not repeat its bitmap. Using {@link Shader.TileMode#REPEAT} or
+ * {@link Shader.TileMode#MIRROR} the bitmap can be repeated (or tiled) if the bitmap
+ * is smaller than this drawable.
+ *
+ * @param mode The repeat mode for this drawable.
+ *
+ * @see #setTileModeY(android.graphics.Shader.TileMode)
+ * @see #setTileModeXY(android.graphics.Shader.TileMode, android.graphics.Shader.TileMode)
+ */
public void setTileModeX(Shader.TileMode mode) {
setTileModeXY(mode, mBitmapState.mTileModeY);
}
+ /**
+ * Sets the repeat behavior of this drawable on the Y axis. By default, the drawable
+ * does not repeat its bitmap. Using {@link Shader.TileMode#REPEAT} or
+ * {@link Shader.TileMode#MIRROR} the bitmap can be repeated (or tiled) if the bitmap
+ * is smaller than this drawable.
+ *
+ * @param mode The repeat mode for this drawable.
+ *
+ * @see #setTileModeX(android.graphics.Shader.TileMode)
+ * @see #setTileModeXY(android.graphics.Shader.TileMode, android.graphics.Shader.TileMode)
+ */
public final void setTileModeY(Shader.TileMode mode) {
setTileModeXY(mBitmapState.mTileModeX, mode);
}
+ /**
+ * Sets the repeat behavior of this drawable on both axis. By default, the drawable
+ * does not repeat its bitmap. Using {@link Shader.TileMode#REPEAT} or
+ * {@link Shader.TileMode#MIRROR} the bitmap can be repeated (or tiled) if the bitmap
+ * is smaller than this drawable.
+ *
+ * @param xmode The X repeat mode for this drawable.
+ * @param ymode The Y repeat mode for this drawable.
+ *
+ * @see #setTileModeX(android.graphics.Shader.TileMode)
+ * @see #setTileModeY(android.graphics.Shader.TileMode)
+ */
public void setTileModeXY(Shader.TileMode xmode, Shader.TileMode ymode) {
final BitmapState state = mBitmapState;
- if (state.mPaint.getShader() == null ||
- state.mTileModeX != xmode || state.mTileModeY != ymode) {
+ if (state.mTileModeX != xmode || state.mTileModeY != ymode) {
state.mTileModeX = xmode;
state.mTileModeY = ymode;
- mRebuildShader = true;
+ state.mRebuildShader = true;
invalidateSelf();
}
}
@@ -309,33 +367,33 @@ public class BitmapDrawable extends Drawable {
Bitmap bitmap = mBitmap;
if (bitmap != null) {
final BitmapState state = mBitmapState;
- if (mRebuildShader) {
+ if (state.mRebuildShader) {
Shader.TileMode tmx = state.mTileModeX;
Shader.TileMode tmy = state.mTileModeY;
if (tmx == null && tmy == null) {
state.mPaint.setShader(null);
} else {
- Shader s = new BitmapShader(bitmap,
+ state.mPaint.setShader(new BitmapShader(bitmap,
tmx == null ? Shader.TileMode.CLAMP : tmx,
- tmy == null ? Shader.TileMode.CLAMP : tmy);
- state.mPaint.setShader(s);
+ tmy == null ? Shader.TileMode.CLAMP : tmy));
}
- mRebuildShader = false;
+ state.mRebuildShader = false;
copyBounds(mDstRect);
}
Shader shader = state.mPaint.getShader();
if (shader == null) {
if (mApplyGravity) {
+ final int layoutDirection = getResolvedLayoutDirectionSelf();
Gravity.apply(state.mGravity, mBitmapWidth, mBitmapHeight,
- getBounds(), mDstRect);
+ getBounds(), mDstRect, layoutDirection);
mApplyGravity = false;
}
canvas.drawBitmap(bitmap, null, mDstRect, state.mPaint);
} else {
if (mApplyGravity) {
- mDstRect.set(getBounds());
+ copyBounds(mDstRect);
mApplyGravity = false;
}
canvas.drawRect(mDstRect, state.mPaint);
@@ -345,8 +403,11 @@ public class BitmapDrawable extends Drawable {
@Override
public void setAlpha(int alpha) {
- mBitmapState.mPaint.setAlpha(alpha);
- invalidateSelf();
+ int oldAlpha = mBitmapState.mPaint.getAlpha();
+ if (alpha != oldAlpha) {
+ mBitmapState.mPaint.setAlpha(alpha);
+ invalidateSelf();
+ }
}
@Override
@@ -448,9 +509,10 @@ public class BitmapDrawable extends Drawable {
int mChangingConfigurations;
int mGravity = Gravity.FILL;
Paint mPaint = new Paint(DEFAULT_PAINT_FLAGS);
- Shader.TileMode mTileModeX;
- Shader.TileMode mTileModeY;
+ Shader.TileMode mTileModeX = null;
+ Shader.TileMode mTileModeY = null;
int mTargetDensity = DisplayMetrics.DENSITY_DEFAULT;
+ boolean mRebuildShader;
BitmapState(Bitmap bitmap) {
mBitmap = bitmap;
@@ -464,18 +526,19 @@ public class BitmapDrawable extends Drawable {
mTileModeY = bitmapState.mTileModeY;
mTargetDensity = bitmapState.mTargetDensity;
mPaint = new Paint(bitmapState.mPaint);
+ mRebuildShader = bitmapState.mRebuildShader;
}
@Override
public Drawable newDrawable() {
return new BitmapDrawable(this, null);
}
-
+
@Override
public Drawable newDrawable(Resources res) {
return new BitmapDrawable(this, res);
}
-
+
@Override
public int getChangingConfigurations() {
return mChangingConfigurations;
@@ -489,6 +552,6 @@ public class BitmapDrawable extends Drawable {
} else {
mTargetDensity = state.mTargetDensity;
}
- setBitmap(state.mBitmap);
+ setBitmap(state != null ? state.mBitmap : null);
}
}
diff --git a/graphics/java/android/graphics/drawable/ClipDrawable.java b/graphics/java/android/graphics/drawable/ClipDrawable.java
index b333e01..29edc04 100644
--- a/graphics/java/android/graphics/drawable/ClipDrawable.java
+++ b/graphics/java/android/graphics/drawable/ClipDrawable.java
@@ -24,6 +24,7 @@ import android.content.res.TypedArray;
import android.graphics.*;
import android.view.Gravity;
import android.util.AttributeSet;
+import android.view.View;
import java.io.IOException;
@@ -209,7 +210,8 @@ public class ClipDrawable extends Drawable implements Drawable.Callback {
if ((mClipState.mOrientation & VERTICAL) != 0) {
h -= (h - ih) * (10000 - level) / 10000;
}
- Gravity.apply(mClipState.mGravity, w, h, bounds, r);
+ final int layoutDirection = getResolvedLayoutDirectionSelf();
+ Gravity.apply(mClipState.mGravity, w, h, bounds, r, layoutDirection);
if (w > 0 && h > 0) {
canvas.save();
diff --git a/graphics/java/android/graphics/drawable/ColorDrawable.java b/graphics/java/android/graphics/drawable/ColorDrawable.java
index 4418e02..88c9155 100644
--- a/graphics/java/android/graphics/drawable/ColorDrawable.java
+++ b/graphics/java/android/graphics/drawable/ColorDrawable.java
@@ -111,8 +111,11 @@ public class ColorDrawable extends Drawable {
alpha += alpha >> 7; // make it 0..256
int baseAlpha = mState.mBaseColor >>> 24;
int useAlpha = baseAlpha * alpha >> 8;
+ int oldUseColor = mState.mUseColor;
mState.mUseColor = (mState.mBaseColor << 8 >>> 8) | (useAlpha << 24);
- invalidateSelf();
+ if (oldUseColor != mState.mUseColor) {
+ invalidateSelf();
+ }
}
/**
diff --git a/graphics/java/android/graphics/drawable/Drawable.java b/graphics/java/android/graphics/drawable/Drawable.java
index 159f371e..0a3deb1 100644
--- a/graphics/java/android/graphics/drawable/Drawable.java
+++ b/graphics/java/android/graphics/drawable/Drawable.java
@@ -36,6 +36,7 @@ import android.util.DisplayMetrics;
import android.util.StateSet;
import android.util.TypedValue;
import android.util.Xml;
+import android.view.View;
import java.io.IOException;
import java.io.InputStream;
@@ -288,6 +289,20 @@ 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 {
+ /**
+ * A Drawable can call this to get the resolved layout direction of the <var>who</var>.
+ *
+ * @param who The drawable being queried.
+ */
+ public int getResolvedLayoutDirection(Drawable who);
+ }
+
+ /**
* Bind a {@link Callback} object to this Drawable. Required for clients
* that want to support animated drawables.
*
@@ -364,6 +379,20 @@ 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();
+ if (callback == null || !(callback instanceof Callback2)) {
+ return View.LAYOUT_DIRECTION_LTR;
+ }
+ return ((Callback2) callback).getResolvedLayoutDirection(this);
+ }
+
+ /**
* Specify an alpha value for the drawable. 0 means fully transparent, and
* 255 means fully opaque.
*/
diff --git a/graphics/java/android/graphics/drawable/DrawableContainer.java b/graphics/java/android/graphics/drawable/DrawableContainer.java
index a9414e8..b0f7fd3 100644
--- a/graphics/java/android/graphics/drawable/DrawableContainer.java
+++ b/graphics/java/android/graphics/drawable/DrawableContainer.java
@@ -167,6 +167,7 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
}
if (mCurrDrawable != null) {
mCurrDrawable.jumpToCurrentState();
+ mCurrDrawable.setAlpha(mAlpha);
}
if (mExitAnimationEnd != 0) {
mExitAnimationEnd = 0;
diff --git a/graphics/java/android/graphics/drawable/GradientDrawable.java b/graphics/java/android/graphics/drawable/GradientDrawable.java
index 33f050c..de0fabc 100644
--- a/graphics/java/android/graphics/drawable/GradientDrawable.java
+++ b/graphics/java/android/graphics/drawable/GradientDrawable.java
@@ -240,16 +240,19 @@ public class GradientDrawable extends Drawable {
public void setGradientCenter(float x, float y) {
mGradientState.setGradientCenter(x, y);
+ mRectIsDirty = true;
invalidateSelf();
}
public void setGradientRadius(float gradientRadius) {
mGradientState.setGradientRadius(gradientRadius);
+ mRectIsDirty = true;
invalidateSelf();
}
public void setUseLevel(boolean useLevel) {
mGradientState.mUseLevel = useLevel;
+ mRectIsDirty = true;
invalidateSelf();
}
@@ -931,6 +934,7 @@ public class GradientDrawable extends Drawable {
mPositions = state.mPositions.clone();
}
mHasSolidColor = state.mHasSolidColor;
+ mSolidColor = state.mSolidColor;
mStrokeWidth = state.mStrokeWidth;
mStrokeColor = state.mStrokeColor;
mStrokeDashWidth = state.mStrokeDashWidth;
diff --git a/graphics/java/android/graphics/drawable/LayerDrawable.java b/graphics/java/android/graphics/drawable/LayerDrawable.java
index 49dbbca..6698d31 100644
--- a/graphics/java/android/graphics/drawable/LayerDrawable.java
+++ b/graphics/java/android/graphics/drawable/LayerDrawable.java
@@ -277,10 +277,19 @@ public class LayerDrawable extends Drawable implements Drawable.Callback {
*/
public boolean setDrawableByLayerId(int id, Drawable drawable) {
final ChildDrawable[] layers = mLayerState.mChildren;
- drawable.setCallback(this);
for (int i = mLayerState.mNum - 1; i >= 0; i--) {
if (layers[i].mId == id) {
+ if (layers[i].mDrawable != null) {
+ if (drawable != null) {
+ Rect bounds = layers[i].mDrawable.getBounds();
+ drawable.setBounds(bounds);
+ }
+ layers[i].mDrawable.setCallback(null);
+ }
+ if (drawable != null) {
+ drawable.setCallback(this);
+ }
layers[i].mDrawable = drawable;
return true;
}
diff --git a/graphics/java/android/graphics/drawable/NinePatchDrawable.java b/graphics/java/android/graphics/drawable/NinePatchDrawable.java
index a5175c5..c32a5b6 100644
--- a/graphics/java/android/graphics/drawable/NinePatchDrawable.java
+++ b/graphics/java/android/graphics/drawable/NinePatchDrawable.java
@@ -214,10 +214,8 @@ public class NinePatchDrawable extends Drawable {
@Override
public void setFilterBitmap(boolean filter) {
- // at the moment, we see no quality improvement, but a big slowdown
- // with filtering, so ignore this call for now
- //
- //getPaint().setFilterBitmap(filter);
+ getPaint().setFilterBitmap(filter);
+ invalidateSelf();
}
@Override
diff --git a/graphics/java/android/graphics/drawable/RotateDrawable.java b/graphics/java/android/graphics/drawable/RotateDrawable.java
index 4f74b37..e987679 100644
--- a/graphics/java/android/graphics/drawable/RotateDrawable.java
+++ b/graphics/java/android/graphics/drawable/RotateDrawable.java
@@ -83,7 +83,7 @@ public class RotateDrawable extends Drawable implements Drawable.Callback {
float px = st.mPivotXRel ? (w * st.mPivotX) : st.mPivotX;
float py = st.mPivotYRel ? (h * st.mPivotY) : st.mPivotY;
- canvas.rotate(st.mCurrentDegrees, px, py);
+ canvas.rotate(st.mCurrentDegrees, px + bounds.left, py + bounds.top);
st.mDrawable.draw(canvas);
diff --git a/graphics/java/android/graphics/drawable/ScaleDrawable.java b/graphics/java/android/graphics/drawable/ScaleDrawable.java
index a7ed0d0..5fd5a16 100644
--- a/graphics/java/android/graphics/drawable/ScaleDrawable.java
+++ b/graphics/java/android/graphics/drawable/ScaleDrawable.java
@@ -24,6 +24,7 @@ import android.content.res.TypedArray;
import android.graphics.*;
import android.view.Gravity;
import android.util.AttributeSet;
+import android.view.View;
import java.io.IOException;
@@ -221,7 +222,8 @@ public class ScaleDrawable extends Drawable implements Drawable.Callback {
final int ih = min ? mScaleState.mDrawable.getIntrinsicHeight() : 0;
h -= (int) ((h - ih) * (10000 - level) * mScaleState.mScaleHeight / 10000);
}
- Gravity.apply(mScaleState.mGravity, w, h, bounds, r);
+ final int layoutDirection = getResolvedLayoutDirectionSelf();
+ Gravity.apply(mScaleState.mGravity, w, h, bounds, r, layoutDirection);
if (w > 0 && h > 0) {
mScaleState.mDrawable.setBounds(r.left, r.top, r.right, r.bottom);
diff --git a/graphics/java/android/graphics/drawable/TransitionDrawable.java b/graphics/java/android/graphics/drawable/TransitionDrawable.java
index 9a3ca40..483fa56 100644
--- a/graphics/java/android/graphics/drawable/TransitionDrawable.java
+++ b/graphics/java/android/graphics/drawable/TransitionDrawable.java
@@ -187,8 +187,20 @@ public class TransitionDrawable extends LayerDrawable implements Drawable.Callba
final int alpha = mAlpha;
final boolean crossFade = mCrossFade;
final ChildDrawable[] array = mLayerState.mChildren;
- Drawable d;
+ if (done) {
+ // the setAlpha() calls below trigger invalidation and redraw. If we're done, just draw
+ // the appropriate drawable[s] and return
+ if (!crossFade || alpha == 0) {
+ array[0].mDrawable.draw(canvas);
+ }
+ if (alpha == 0xFF) {
+ array[1].mDrawable.draw(canvas);
+ }
+ return;
+ }
+
+ Drawable d;
d = array[0].mDrawable;
if (crossFade) {
d.setAlpha(255 - alpha);
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java
index 4b8c58e..12e5ada 100644
--- a/graphics/java/android/renderscript/Allocation.java
+++ b/graphics/java/android/renderscript/Allocation.java
@@ -67,6 +67,22 @@ public class Allocation extends BaseObj {
Type mType;
Bitmap mBitmap;
int mUsage;
+ Allocation mAdaptedAllocation;
+
+ boolean mConstrainedLOD;
+ boolean mConstrainedFace;
+ boolean mConstrainedY;
+ boolean mConstrainedZ;
+ int mSelectedY;
+ int mSelectedZ;
+ int mSelectedLOD;
+ Type.CubemapFace mSelectedFace = Type.CubemapFace.POSITIVE_X;
+
+ int mCurrentDimX;
+ int mCurrentDimY;
+ int mCurrentDimZ;
+ int mCurrentCount;
+
/**
* The usage of the allocation. These signal to renderscript
@@ -79,7 +95,7 @@ public class Allocation extends BaseObj {
/**
* GRAPHICS_TEXTURE The allcation will be used as a texture
- * source by one or more graphcics programs.
+ * source by one or more graphics programs.
*
*/
public static final int USAGE_GRAPHICS_TEXTURE = 0x0002;
@@ -99,6 +115,13 @@ public class Allocation extends BaseObj {
*/
public static final int USAGE_GRAPHICS_CONSTANTS = 0x0008;
+ /**
+ * USAGE_GRAPHICS_RENDER_TARGET The allcation will be used as a
+ * target for offscreen rendering
+ *
+ */
+ public static final int USAGE_GRAPHICS_RENDER_TARGET = 0x0010;
+
/**
* Controls mipmap behavior when using the bitmap creation and
@@ -132,15 +155,41 @@ public class Allocation extends BaseObj {
}
}
+
+ private int getIDSafe() {
+ if (mAdaptedAllocation != null) {
+ return mAdaptedAllocation.getID();
+ }
+ return getID();
+ }
+
+ private void updateCacheInfo(Type t) {
+ mCurrentDimX = t.getX();
+ mCurrentDimY = t.getY();
+ mCurrentDimZ = t.getZ();
+ mCurrentCount = mCurrentDimX;
+ if (mCurrentDimY > 1) {
+ mCurrentCount *= mCurrentDimY;
+ }
+ if (mCurrentDimZ > 1) {
+ mCurrentCount *= mCurrentDimZ;
+ }
+ }
+
Allocation(int id, RenderScript rs, Type t, int usage) {
super(id, rs);
if ((usage & ~(USAGE_SCRIPT |
USAGE_GRAPHICS_TEXTURE |
USAGE_GRAPHICS_VERTEX |
- USAGE_GRAPHICS_CONSTANTS)) != 0) {
+ USAGE_GRAPHICS_CONSTANTS |
+ USAGE_GRAPHICS_RENDER_TARGET)) != 0) {
throw new RSIllegalArgumentException("Unknown usage specified.");
}
mType = t;
+
+ if (t != null) {
+ updateCacheInfo(t);
+ }
}
private void validateIsInt32() {
@@ -202,6 +251,7 @@ public class Allocation extends BaseObj {
if(typeID != 0) {
mType = new Type(typeID, mRS);
mType.updateFromNative();
+ updateCacheInfo(mType);
}
}
@@ -220,21 +270,21 @@ public class Allocation extends BaseObj {
throw new RSIllegalArgumentException("Source must be exactly one usage type.");
}
mRS.validate();
- mRS.nAllocationSyncAll(getID(), srcLocation);
+ mRS.nAllocationSyncAll(getIDSafe(), srcLocation);
}
public void copyFrom(BaseObj[] d) {
mRS.validate();
validateIsObject();
- if (d.length != mType.getCount()) {
+ if (d.length != mCurrentCount) {
throw new RSIllegalArgumentException("Array size mismatch, allocation sizeX = " +
- mType.getCount() + ", array length = " + d.length);
+ mCurrentCount + ", array length = " + d.length);
}
int i[] = new int[d.length];
for (int ct=0; ct < d.length; ct++) {
i[ct] = d[ct].getID();
}
- copy1DRangeFromUnchecked(0, mType.getCount(), i);
+ copy1DRangeFromUnchecked(0, mCurrentCount, i);
}
private void validateBitmapFormat(Bitmap b) {
@@ -284,8 +334,7 @@ public class Allocation extends BaseObj {
}
private void validateBitmapSize(Bitmap b) {
- if(mType.getX() != b.getWidth() ||
- mType.getY() != b.getHeight()) {
+ if((mCurrentDimX != b.getWidth()) || (mCurrentDimY != b.getHeight())) {
throw new RSIllegalArgumentException("Cannot update allocation from bitmap, sizes mismatch");
}
}
@@ -299,7 +348,7 @@ public class Allocation extends BaseObj {
*/
public void copyFromUnchecked(int[] d) {
mRS.validate();
- copy1DRangeFromUnchecked(0, mType.getCount(), d);
+ copy1DRangeFromUnchecked(0, mCurrentCount, d);
}
/**
* Copy an allocation from an array. This variant is not type
@@ -310,7 +359,7 @@ public class Allocation extends BaseObj {
*/
public void copyFromUnchecked(short[] d) {
mRS.validate();
- copy1DRangeFromUnchecked(0, mType.getCount(), d);
+ copy1DRangeFromUnchecked(0, mCurrentCount, d);
}
/**
* Copy an allocation from an array. This variant is not type
@@ -321,7 +370,7 @@ public class Allocation extends BaseObj {
*/
public void copyFromUnchecked(byte[] d) {
mRS.validate();
- copy1DRangeFromUnchecked(0, mType.getCount(), d);
+ copy1DRangeFromUnchecked(0, mCurrentCount, d);
}
/**
* Copy an allocation from an array. This variant is not type
@@ -332,7 +381,7 @@ public class Allocation extends BaseObj {
*/
public void copyFromUnchecked(float[] d) {
mRS.validate();
- copy1DRangeFromUnchecked(0, mType.getCount(), d);
+ copy1DRangeFromUnchecked(0, mCurrentCount, d);
}
/**
@@ -344,7 +393,7 @@ public class Allocation extends BaseObj {
*/
public void copyFrom(int[] d) {
mRS.validate();
- copy1DRangeFrom(0, mType.getCount(), d);
+ copy1DRangeFrom(0, mCurrentCount, d);
}
/**
@@ -356,7 +405,7 @@ public class Allocation extends BaseObj {
*/
public void copyFrom(short[] d) {
mRS.validate();
- copy1DRangeFrom(0, mType.getCount(), d);
+ copy1DRangeFrom(0, mCurrentCount, d);
}
/**
@@ -368,7 +417,7 @@ public class Allocation extends BaseObj {
*/
public void copyFrom(byte[] d) {
mRS.validate();
- copy1DRangeFrom(0, mType.getCount(), d);
+ copy1DRangeFrom(0, mCurrentCount, d);
}
/**
@@ -380,7 +429,7 @@ public class Allocation extends BaseObj {
*/
public void copyFrom(float[] d) {
mRS.validate();
- copy1DRangeFrom(0, mType.getCount(), d);
+ copy1DRangeFrom(0, mCurrentCount, d);
}
/**
@@ -412,8 +461,7 @@ public class Allocation extends BaseObj {
throw new RSIllegalArgumentException("Field packer length " + data.length +
" not divisible by element size " + eSize + ".");
}
- data1DChecks(xoff, count, data.length, data.length);
- mRS.nAllocationData1D(getID(), xoff, 0, count, data, data.length);
+ copy1DRangeFromUnchecked(xoff, count, data);
}
/**
@@ -440,7 +488,8 @@ public class Allocation extends BaseObj {
" does not match component size " + eSize + ".");
}
- mRS.nAllocationElementData1D(getID(), xoff, 0, component_number, data, data.length);
+ mRS.nAllocationElementData1D(getIDSafe(), xoff, mSelectedLOD,
+ component_number, data, data.length);
}
private void data1DChecks(int off, int count, int len, int dataSize) {
@@ -451,11 +500,11 @@ public class Allocation extends BaseObj {
if(count < 1) {
throw new RSIllegalArgumentException("Count must be >= 1.");
}
- if((off + count) > mType.getCount()) {
- throw new RSIllegalArgumentException("Overflow, Available count " + mType.getCount() +
+ if((off + count) > mCurrentCount) {
+ throw new RSIllegalArgumentException("Overflow, Available count " + mCurrentCount +
", got " + count + " at offset " + off + ".");
}
- if((len) < dataSize) {
+ if(len < dataSize) {
throw new RSIllegalArgumentException("Array too small for allocation type.");
}
}
@@ -486,7 +535,7 @@ public class Allocation extends BaseObj {
public void copy1DRangeFromUnchecked(int off, int count, int[] d) {
int dataSize = mType.mElement.getSizeBytes() * count;
data1DChecks(off, count, d.length * 4, dataSize);
- mRS.nAllocationData1D(getID(), off, 0, count, d, dataSize);
+ mRS.nAllocationData1D(getIDSafe(), off, mSelectedLOD, count, d, dataSize);
}
/**
* Copy part of an allocation from an array. This variant is
@@ -500,7 +549,7 @@ public class Allocation extends BaseObj {
public void copy1DRangeFromUnchecked(int off, int count, short[] d) {
int dataSize = mType.mElement.getSizeBytes() * count;
data1DChecks(off, count, d.length * 2, dataSize);
- mRS.nAllocationData1D(getID(), off, 0, count, d, dataSize);
+ mRS.nAllocationData1D(getIDSafe(), off, mSelectedLOD, count, d, dataSize);
}
/**
* Copy part of an allocation from an array. This variant is
@@ -514,7 +563,7 @@ public class Allocation extends BaseObj {
public void copy1DRangeFromUnchecked(int off, int count, byte[] d) {
int dataSize = mType.mElement.getSizeBytes() * count;
data1DChecks(off, count, d.length, dataSize);
- mRS.nAllocationData1D(getID(), off, 0, count, d, dataSize);
+ mRS.nAllocationData1D(getIDSafe(), off, mSelectedLOD, count, d, dataSize);
}
/**
* Copy part of an allocation from an array. This variant is
@@ -528,7 +577,7 @@ public class Allocation extends BaseObj {
public void copy1DRangeFromUnchecked(int off, int count, float[] d) {
int dataSize = mType.mElement.getSizeBytes() * count;
data1DChecks(off, count, d.length * 4, dataSize);
- mRS.nAllocationData1D(getID(), off, 0, count, d, dataSize);
+ mRS.nAllocationData1D(getIDSafe(), off, mSelectedLOD, count, d, dataSize);
}
/**
@@ -580,30 +629,49 @@ public class Allocation extends BaseObj {
*
* @param off The offset of the first element to be copied.
* @param count The number of elements to be copied.
- * @param d the source data array
+ * @param d the source data array.
*/
public void copy1DRangeFrom(int off, int count, float[] d) {
validateIsFloat32();
copy1DRangeFromUnchecked(off, count, d);
}
+ /**
+ * Copy part of an allocation from another allocation.
+ *
+ * @param off The offset of the first element to be copied.
+ * @param count The number of elements to be copied.
+ * @param data the source data allocation.
+ * @param dataOff off The offset of the first element in data to
+ * be copied.
+ */
+ 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,
+ data.mSelectedLOD, data.mSelectedFace.mID);
+ }
+
private void validate2DRange(int xoff, int yoff, int w, int h) {
- if (xoff < 0 || yoff < 0) {
- throw new RSIllegalArgumentException("Offset cannot be negative.");
- }
- if (h < 0 || w < 0) {
- throw new RSIllegalArgumentException("Height or width cannot be negative.");
- }
- if ((xoff + w) > mType.mDimX ||
- (yoff + h) > mType.mDimY) {
- throw new RSIllegalArgumentException("Updated region larger than allocation.");
+ if (mAdaptedAllocation != null) {
+
+ } else {
+
+ if (xoff < 0 || yoff < 0) {
+ throw new RSIllegalArgumentException("Offset cannot be negative.");
+ }
+ if (h < 0 || w < 0) {
+ throw new RSIllegalArgumentException("Height or width cannot be negative.");
+ }
+ if (((xoff + w) > mCurrentDimX) || ((yoff + h) > mCurrentDimY)) {
+ throw new RSIllegalArgumentException("Updated region larger than allocation.");
+ }
}
}
/**
- * Copy a rectanglular region from the array into the
- * allocation. The incoming array is assumed to be tightly
- * packed.
+ * Copy a rectangular region from the array into the allocation.
+ * The incoming array is assumed to be tightly packed.
*
* @param xoff X offset of the region to update
* @param yoff Y offset of the region to update
@@ -614,25 +682,51 @@ public class Allocation extends BaseObj {
public void copy2DRangeFrom(int xoff, int yoff, int w, int h, byte[] data) {
mRS.validate();
validate2DRange(xoff, yoff, w, h);
- mRS.nAllocationData2D(getID(), xoff, yoff, 0, 0, w, h, data, data.length);
+ mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID,
+ w, h, data, data.length);
}
public void copy2DRangeFrom(int xoff, int yoff, int w, int h, short[] data) {
mRS.validate();
validate2DRange(xoff, yoff, w, h);
- mRS.nAllocationData2D(getID(), xoff, yoff, 0, 0, w, h, data, data.length * 2);
+ mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID,
+ w, h, data, data.length * 2);
}
public void copy2DRangeFrom(int xoff, int yoff, int w, int h, int[] data) {
mRS.validate();
validate2DRange(xoff, yoff, w, h);
- mRS.nAllocationData2D(getID(), xoff, yoff, 0, 0, w, h, data, data.length * 4);
+ mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID,
+ w, h, data, data.length * 4);
}
public void copy2DRangeFrom(int xoff, int yoff, int w, int h, float[] data) {
mRS.validate();
validate2DRange(xoff, yoff, w, h);
- mRS.nAllocationData2D(getID(), xoff, yoff, 0, 0, w, h, data, data.length * 4);
+ mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID,
+ w, h, data, data.length * 4);
+ }
+
+ /**
+ * Copy a rectangular region into the allocation from another
+ * allocation.
+ *
+ * @param xoff X offset of the region to update.
+ * @param yoff Y offset of the region to update.
+ * @param w Width of the incoming region to update.
+ * @param h Height of the incoming region to update.
+ * @param data source allocation.
+ * @param dataXoff X offset in data of the region to update.
+ * @param dataYoff Y offset in data of the region to update.
+ */
+ public void copy2DRangeFrom(int xoff, int yoff, int w, int h,
+ Allocation data, int dataXoff, int dataYoff) {
+ mRS.validate();
+ validate2DRange(xoff, yoff, w, h);
+ mRS.nAllocationData2D(getIDSafe(), xoff, yoff,
+ mSelectedLOD, mSelectedFace.mID,
+ w, h, data.getID(), dataXoff, dataYoff,
+ data.mSelectedLOD, data.mSelectedFace.mID);
}
/**
@@ -648,10 +742,16 @@ public class Allocation extends BaseObj {
mRS.validate();
validateBitmapFormat(data);
validate2DRange(xoff, yoff, data.getWidth(), data.getHeight());
- mRS.nAllocationData2D(getID(), xoff, yoff, 0, 0, data);
+ mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, data);
}
+ /**
+ * Copy from the Allocation into a Bitmap. The bitmap must
+ * match the dimensions of the Allocation.
+ *
+ * @param b The bitmap to be set from the Allocation.
+ */
public void copyTo(Bitmap b) {
mRS.validate();
validateBitmapFormat(b);
@@ -659,24 +759,52 @@ public class Allocation extends BaseObj {
mRS.nAllocationCopyToBitmap(getID(), b);
}
+ /**
+ * Copy from the Allocation into a byte array. The array must
+ * be at least as large as the Allocation. The allocation must
+ * be of an 8 bit elemental type.
+ *
+ * @param d The array to be set from the Allocation.
+ */
public void copyTo(byte[] d) {
validateIsInt8();
mRS.validate();
mRS.nAllocationRead(getID(), d);
}
+ /**
+ * Copy from the Allocation into a short array. The array must
+ * be at least as large as the Allocation. The allocation must
+ * be of an 16 bit elemental type.
+ *
+ * @param d The array to be set from the Allocation.
+ */
public void copyTo(short[] d) {
validateIsInt16();
mRS.validate();
mRS.nAllocationRead(getID(), d);
}
+ /**
+ * Copy from the Allocation into a int array. The array must be
+ * at least as large as the Allocation. The allocation must be
+ * of an 32 bit elemental type.
+ *
+ * @param d The array to be set from the Allocation.
+ */
public void copyTo(int[] d) {
validateIsInt32();
mRS.validate();
mRS.nAllocationRead(getID(), d);
}
+ /**
+ * Copy from the Allocation into a float array. The array must
+ * be at least as large as the Allocation. The allocation must
+ * be of an 32 bit float elemental type.
+ *
+ * @param d The array to be set from the Allocation.
+ */
public void copyTo(float[] d) {
validateIsFloat32();
mRS.validate();
@@ -705,6 +833,7 @@ public class Allocation extends BaseObj {
int typeID = mRS.nAllocationGetType(getID());
mType = new Type(typeID, mRS);
mType.updateFromNative();
+ updateCacheInfo(mType);
}
/*
@@ -1003,15 +1132,15 @@ public class Allocation extends BaseObj {
Allocation cubemap = Allocation.createTyped(rs, t, mips, usage);
AllocationAdapter adapter = AllocationAdapter.create2D(rs, cubemap);
- adapter.setFace(Type.CubemapFace.POSITVE_X);
+ adapter.setFace(Type.CubemapFace.POSITIVE_X);
adapter.copyFrom(xpos);
adapter.setFace(Type.CubemapFace.NEGATIVE_X);
adapter.copyFrom(xneg);
- adapter.setFace(Type.CubemapFace.POSITVE_Y);
+ adapter.setFace(Type.CubemapFace.POSITIVE_Y);
adapter.copyFrom(ypos);
adapter.setFace(Type.CubemapFace.NEGATIVE_Y);
adapter.copyFrom(yneg);
- adapter.setFace(Type.CubemapFace.POSITVE_Z);
+ adapter.setFace(Type.CubemapFace.POSITIVE_Z);
adapter.copyFrom(zpos);
adapter.setFace(Type.CubemapFace.NEGATIVE_Z);
adapter.copyFrom(zneg);
diff --git a/graphics/java/android/renderscript/AllocationAdapter.java b/graphics/java/android/renderscript/AllocationAdapter.java
index f2fedea..d38f2df 100644
--- a/graphics/java/android/renderscript/AllocationAdapter.java
+++ b/graphics/java/android/renderscript/AllocationAdapter.java
@@ -17,196 +17,234 @@
package android.renderscript;
import android.content.res.Resources;
-import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
-import android.util.Log;
import android.util.TypedValue;
/**
*
**/
public class AllocationAdapter extends Allocation {
- private int mSelectedDimX;
- private int mSelectedDimY;
- private int mSelectedCount;
- private Allocation mAlloc;
-
- private int mSelectedLOD = 0;
- private Type.CubemapFace mSelectedFace = Type.CubemapFace.POSITVE_X;;
-
AllocationAdapter(int id, RenderScript rs, Allocation alloc) {
- super(id, rs, null, alloc.mUsage);
- Type t = alloc.getType();
- mSelectedDimX = t.getX();
- mSelectedDimY = t.getY();
- mSelectedCount = t.getCount();
+ super(id, rs, alloc.mType, alloc.mUsage);
+ mAdaptedAllocation = alloc;
}
-
- public void copyFrom(BaseObj[] d) {
- mRS.validate();
- if (d.length != mSelectedCount) {
- throw new RSIllegalArgumentException("Array size mismatch, allocation size = " +
- mSelectedCount + ", array length = " + d.length);
- }
- int i[] = new int[d.length];
- for (int ct=0; ct < d.length; ct++) {
- i[ct] = d[ct].getID();
- }
- subData1D(0, mType.getCount(), i);
+ int getID() {
+ throw new RSInvalidStateException(
+ "This operation is not supported with adapters at this time.");
}
- void validateBitmap(Bitmap b) {
- mRS.validate();
- if(mSelectedDimX != b.getWidth() ||
- mSelectedDimY != b.getHeight()) {
- throw new RSIllegalArgumentException("Cannot update allocation from bitmap, sizes mismatch");
- }
- }
-
- public void copyFrom(int[] d) {
- mRS.validate();
- subData1D(0, mSelectedCount, d);
- }
- public void copyFrom(short[] d) {
- mRS.validate();
- subData1D(0, mSelectedCount, d);
- }
- public void copyFrom(byte[] d) {
- mRS.validate();
- subData1D(0, mSelectedCount, d);
- }
- public void copyFrom(float[] d) {
- mRS.validate();
- subData1D(0, mSelectedCount, d);
- }
- public void copyFrom(Bitmap b) {
- validateBitmap(b);
- mRS.nAllocationCopyFromBitmap(getID(), b);
- }
-
- public void copyTo(Bitmap b) {
- validateBitmap(b);
- mRS.nAllocationCopyToBitmap(getID(), b);
- }
-
-
+ /**
+ * @hide
+ */
public void subData(int xoff, FieldPacker fp) {
- int eSize = mType.mElement.getSizeBytes();
- final byte[] data = fp.getData();
-
- int count = data.length / eSize;
- if ((eSize * count) != data.length) {
- throw new RSIllegalArgumentException("Field packer length " + data.length +
- " not divisible by element size " + eSize + ".");
- }
- data1DChecks(xoff, count, data.length, data.length);
- mRS.nAllocationData1D(getID(), xoff, mSelectedLOD, count, data, data.length);
+ super.setFromFieldPacker(xoff, fp);
}
-
-
+ /**
+ * @hide
+ */
public void subElementData(int xoff, int component_number, FieldPacker fp) {
- if (component_number >= mType.mElement.mElements.length) {
- throw new RSIllegalArgumentException("Component_number " + component_number + " out of range.");
- }
- if(xoff < 0) {
- throw new RSIllegalArgumentException("Offset must be >= 0.");
- }
-
- final byte[] data = fp.getData();
- int eSize = mType.mElement.mElements[component_number].getSizeBytes();
-
- if (data.length != eSize) {
- throw new RSIllegalArgumentException("Field packer sizelength " + data.length +
- " does not match component size " + eSize + ".");
- }
-
- mRS.nAllocationElementData1D(getID(), xoff, mSelectedLOD, component_number, data, data.length);
- }
-
- void data1DChecks(int off, int count, int len, int dataSize) {
- mRS.validate();
- if(off < 0) {
- throw new RSIllegalArgumentException("Offset must be >= 0.");
- }
- if(count < 1) {
- throw new RSIllegalArgumentException("Count must be >= 1.");
- }
- if((off + count) > mSelectedDimX * mSelectedDimY) {
- throw new RSIllegalArgumentException("Overflow, Available count " + mType.getCount() +
- ", got " + count + " at offset " + off + ".");
- }
- if((len) < dataSize) {
- throw new RSIllegalArgumentException("Array too small for allocation type.");
- }
+ super.setFromFieldPacker(xoff, component_number, fp);
}
-
+ /**
+ * @hide
+ */
public void subData1D(int off, int count, int[] d) {
- int dataSize = mAlloc.mType.mElement.getSizeBytes() * count;
- data1DChecks(off, count, d.length * 4, dataSize);
- mRS.nAllocationData1D(getID(), off, mSelectedLOD, count, d, dataSize);
+ super.copy1DRangeFrom(off, count, d);
}
+ /**
+ * @hide
+ */
public void subData1D(int off, int count, short[] d) {
- int dataSize = mAlloc.mType.mElement.getSizeBytes() * count;
- data1DChecks(off, count, d.length * 2, dataSize);
- mRS.nAllocationData1D(getID(), off, mSelectedLOD, count, d, dataSize);
+ super.copy1DRangeFrom(off, count, d);
}
+ /**
+ * @hide
+ */
public void subData1D(int off, int count, byte[] d) {
- int dataSize = mAlloc.mType.mElement.getSizeBytes() * count;
- data1DChecks(off, count, d.length, dataSize);
- mRS.nAllocationData1D(getID(), off, mSelectedLOD, count, d, dataSize);
+ super.copy1DRangeFrom(off, count, d);
}
+ /**
+ * @hide
+ */
public void subData1D(int off, int count, float[] d) {
- int dataSize = mAlloc.mType.mElement.getSizeBytes() * count;
- data1DChecks(off, count, d.length * 4, dataSize);
- mRS.nAllocationData1D(getID(), off, mSelectedLOD, count, d, dataSize);
+ super.copy1DRangeFrom(off, count, d);
}
-
-
+ /**
+ * @hide
+ */
public void subData2D(int xoff, int yoff, int w, int h, int[] d) {
- mRS.validate();
- mRS.nAllocationData2D(getID(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, w, h, d, d.length * 4);
+ super.copy2DRangeFrom(xoff, yoff, w, h, d);
}
-
+ /**
+ * @hide
+ */
public void subData2D(int xoff, int yoff, int w, int h, float[] d) {
- mRS.validate();
- mRS.nAllocationData2D(getID(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, w, h, d, d.length * 4);
+ super.copy2DRangeFrom(xoff, yoff, w, h, d);
}
-
+ /**
+ * @hide
+ */
public void readData(int[] d) {
- mRS.validate();
- mRS.nAllocationRead(getID(), d);
+ super.copyTo(d);
}
-
+ /**
+ * @hide
+ */
public void readData(float[] d) {
- mRS.validate();
- mRS.nAllocationRead(getID(), d);
+ super.copyTo(d);
}
+ void initLOD(int lod) {
+ if (lod < 0) {
+ throw new RSIllegalArgumentException("Attempting to set negative lod (" + lod + ").");
+ }
+
+ int tx = mAdaptedAllocation.mType.getX();
+ int ty = mAdaptedAllocation.mType.getY();
+ int tz = mAdaptedAllocation.mType.getZ();
+
+ for (int ct=0; ct < lod; ct++) {
+ if ((tx==1) && (ty == 1) && (tz == 1)) {
+ throw new RSIllegalArgumentException("Attempting to set lod (" + lod + ") out of range.");
+ }
+
+ if (tx > 1) tx >>= 1;
+ if (ty > 1) ty >>= 1;
+ if (tz > 1) tz >>= 1;
+ }
+
+ mCurrentDimX = tx;
+ mCurrentDimY = ty;
+ mCurrentDimZ = tz;
+ mCurrentCount = mCurrentDimX;
+ if (mCurrentDimY > 1) {
+ mCurrentCount *= mCurrentDimY;
+ }
+ if (mCurrentDimZ > 1) {
+ mCurrentCount *= mCurrentDimZ;
+ }
+ mSelectedY = 0;
+ mSelectedZ = 0;
+ }
+
+ /**
+ * Set the active LOD. The LOD must be within the range for the
+ * type being adapted. The base allocation must have mipmaps.
+ *
+ * Because this changes the dimensions of the adapter the
+ * current Y and Z will be reset.
+ *
+ * @param lod The LOD to make active.
+ */
public void setLOD(int lod) {
+ if (!mAdaptedAllocation.getType().hasMipmaps()) {
+ throw new RSInvalidStateException("Cannot set LOD when the allocation type does not include mipmaps.");
+ }
+ if (!mConstrainedLOD) {
+ throw new RSInvalidStateException("Cannot set LOD when the adapter includes mipmaps.");
+ }
+
+ initLOD(lod);
}
+ /**
+ * Set the active Face. The base allocation must be of a type
+ * that includes faces.
+ *
+ * @param cf The face to make active.
+ */
public void setFace(Type.CubemapFace cf) {
+ if (!mAdaptedAllocation.getType().hasFaces()) {
+ throw new RSInvalidStateException("Cannot set Face when the allocation type does not include faces.");
+ }
+ if (!mConstrainedFace) {
+ throw new RSInvalidStateException("Cannot set LOD when the adapter includes mipmaps.");
+ }
+ if (cf == null) {
+ throw new RSIllegalArgumentException("Cannot set null face.");
+ }
+
+ mSelectedFace = cf;
}
+ /**
+ * Set the active Y. The y value must be within the range for
+ * the allocation being adapted. The base allocation must
+ * contain the Y dimension.
+ *
+ * @param y The y to make active.
+ */
public void setY(int y) {
+ if (mAdaptedAllocation.getType().getY() == 0) {
+ throw new RSInvalidStateException("Cannot set Y when the allocation type does not include Y dim.");
+ }
+ if (mAdaptedAllocation.getType().getY() <= y) {
+ throw new RSInvalidStateException("Cannot set Y greater than dimension of allocation.");
+ }
+ if (!mConstrainedY) {
+ throw new RSInvalidStateException("Cannot set Y when the adapter includes Y.");
+ }
+
+ mSelectedY = y;
}
+ /**
+ * Set the active Z. The z value must be within the range for
+ * the allocation being adapted. The base allocation must
+ * contain the Z dimension.
+ *
+ * @param z The z to make active.
+ */
public void setZ(int z) {
+ if (mAdaptedAllocation.getType().getZ() == 0) {
+ throw new RSInvalidStateException("Cannot set Z when the allocation type does not include Z dim.");
+ }
+ if (mAdaptedAllocation.getType().getZ() <= z) {
+ throw new RSInvalidStateException("Cannot set Z greater than dimension of allocation.");
+ }
+ if (!mConstrainedZ) {
+ throw new RSInvalidStateException("Cannot set Z when the adapter includes Z.");
+ }
+
+ mSelectedZ = z;
}
- // creation
- //static public AllocationAdapter create1D(RenderScript rs, Allocation a) {
- //}
+ static public AllocationAdapter create1D(RenderScript rs, Allocation a) {
+ rs.validate();
+ AllocationAdapter aa = new AllocationAdapter(0, rs, a);
+ aa.mConstrainedLOD = true;
+ aa.mConstrainedFace = true;
+ aa.mConstrainedY = true;
+ aa.mConstrainedZ = true;
+ aa.initLOD(0);
+ return aa;
+ }
static public AllocationAdapter create2D(RenderScript rs, Allocation a) {
+ android.util.Log.e("rs", "create2d " + a);
rs.validate();
AllocationAdapter aa = new AllocationAdapter(0, rs, a);
+ aa.mConstrainedLOD = true;
+ aa.mConstrainedFace = true;
+ aa.mConstrainedY = false;
+ aa.mConstrainedZ = true;
+ aa.initLOD(0);
return aa;
}
+ /**
+ * Override the Allocation resize. Resizing adapters is not
+ * allowed and will throw a RSInvalidStateException.
+ *
+ * @param dimX ignored.
+ */
+ public synchronized void resize(int dimX) {
+ throw new RSInvalidStateException("Resize not allowed for Adapters.");
+ }
+
}
diff --git a/graphics/java/android/renderscript/BaseObj.java b/graphics/java/android/renderscript/BaseObj.java
index 8ce1d9a..2e55c48 100644
--- a/graphics/java/android/renderscript/BaseObj.java
+++ b/graphics/java/android/renderscript/BaseObj.java
@@ -24,7 +24,7 @@ import android.util.Log;
* disconecting the object from the native allocation for early cleanup.
*
**/
-class BaseObj {
+public class BaseObj {
BaseObj(int id, RenderScript rs) {
rs.validate();
mRS = rs;
@@ -97,6 +97,13 @@ class BaseObj {
}
}
+ /**
+ * @return name of the renderscript object
+ */
+ public String getName() {
+ return mName;
+ }
+
protected void finalize() throws Throwable {
if (!mDestroyed) {
if(mID != 0 && mRS.isAlive()) {
@@ -134,5 +141,35 @@ class BaseObj {
mName = mRS.nGetName(getID());
}
+ /**
+ * Calculates the hash code value for a BaseObj.
+ *
+ * @return int
+ */
+ @Override
+ public int hashCode() {
+ return mID;
+ }
+
+ /**
+ * Compare the current BaseObj with another BaseObj for equality.
+ *
+ * @param obj The object to check equality with.
+ *
+ * @return boolean
+ */
+ @Override
+ public boolean equals(Object obj) {
+ // Early-out check to see if both BaseObjs are actually the same
+ if (this == obj)
+ return true;
+
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+
+ BaseObj b = (BaseObj) obj;
+ return mID == b.mID;
+ }
}
diff --git a/graphics/java/android/renderscript/Byte2.java b/graphics/java/android/renderscript/Byte2.java
index 7ec6cb0..7df5f2e 100644
--- a/graphics/java/android/renderscript/Byte2.java
+++ b/graphics/java/android/renderscript/Byte2.java
@@ -28,6 +28,11 @@ public class Byte2 {
public Byte2() {
}
+ public Byte2(byte initX, byte initY) {
+ x = initX;
+ y = initY;
+ }
+
public byte x;
public byte y;
}
diff --git a/graphics/java/android/renderscript/Byte3.java b/graphics/java/android/renderscript/Byte3.java
index 7bcd4b4..02a01c1 100644
--- a/graphics/java/android/renderscript/Byte3.java
+++ b/graphics/java/android/renderscript/Byte3.java
@@ -28,6 +28,12 @@ public class Byte3 {
public Byte3() {
}
+ public Byte3(byte initX, byte initY, byte initZ) {
+ x = initX;
+ y = initY;
+ z = initZ;
+ }
+
public byte x;
public byte y;
public byte z;
diff --git a/graphics/java/android/renderscript/Byte4.java b/graphics/java/android/renderscript/Byte4.java
index c6e7f63..a55a696 100644
--- a/graphics/java/android/renderscript/Byte4.java
+++ b/graphics/java/android/renderscript/Byte4.java
@@ -28,6 +28,13 @@ public class Byte4 {
public Byte4() {
}
+ public Byte4(byte initX, byte initY, byte initZ, byte initW) {
+ x = initX;
+ y = initY;
+ z = initZ;
+ w = initW;
+ }
+
public byte x;
public byte y;
public byte z;
diff --git a/graphics/java/android/renderscript/Double2.java b/graphics/java/android/renderscript/Double2.java
new file mode 100644
index 0000000..9f4f328
--- /dev/null
+++ b/graphics/java/android/renderscript/Double2.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.renderscript;
+
+import java.lang.Math;
+import android.util.Log;
+
+
+/**
+ * Class for exposing the native Renderscript double2 type back
+ * to the Android system.
+ *
+ **/
+public class Double2 {
+ public Double2() {
+ }
+
+ public Double2(double initX, double initY) {
+ x = initX;
+ y = initY;
+ }
+
+ public double x;
+ public double y;
+}
+
+
+
+
diff --git a/graphics/java/android/renderscript/Double3.java b/graphics/java/android/renderscript/Double3.java
new file mode 100644
index 0000000..eb55142
--- /dev/null
+++ b/graphics/java/android/renderscript/Double3.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.renderscript;
+
+import java.lang.Math;
+import android.util.Log;
+
+
+/**
+ * Class for exposing the native Renderscript double3 type back
+ * to the Android system.
+ *
+ **/
+public class Double3 {
+ public Double3() {
+ }
+
+ public Double3(double initX, double initY, double initZ) {
+ x = initX;
+ y = initY;
+ z = initZ;
+ }
+
+ public double x;
+ public double y;
+ public double z;
+}
+
+
+
+
diff --git a/graphics/java/android/renderscript/Double4.java b/graphics/java/android/renderscript/Double4.java
new file mode 100644
index 0000000..4755a76
--- /dev/null
+++ b/graphics/java/android/renderscript/Double4.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.renderscript;
+
+import java.lang.Math;
+import android.util.Log;
+
+
+/**
+ * Class for exposing the native Renderscript double4 type back
+ * to the Android system.
+ *
+ **/
+public class Double4 {
+ public Double4() {
+ }
+
+ public Double4(double initX, double initY, double initZ, double initW) {
+ x = initX;
+ y = initY;
+ z = initZ;
+ w = initW;
+ }
+
+ public double x;
+ public double y;
+ public double z;
+ public double w;
+}
+
+
+
diff --git a/graphics/java/android/renderscript/Element.java b/graphics/java/android/renderscript/Element.java
index fae22f0..f844331 100644
--- a/graphics/java/android/renderscript/Element.java
+++ b/graphics/java/android/renderscript/Element.java
@@ -32,8 +32,8 @@ import android.util.Log;
* <p>Complex elements contain a list of sub-elements and names that
* represents a structure of data. The fields can be accessed by name
* from a script or shader. The memory layout is defined and ordered. Data
- * alignment is determinied by the most basic primitive type. i.e. a float4
- * vector will be alligned to sizeof(float) and not sizeof(float4). The
+ * alignment is determined by the most basic primitive type. i.e. a float4
+ * vector will be aligned to sizeof(float) and not sizeof(float4). The
* ordering of elements in memory will be the order in which they were added
* with each component aligned as necessary. No re-ordering will be done.</p>
*
@@ -124,7 +124,8 @@ public class Element extends BaseObj {
PIXEL_A (8),
PIXEL_LA (9),
PIXEL_RGB (10),
- PIXEL_RGBA (11);
+ PIXEL_RGBA (11),
+ PIXEL_DEPTH (12);
int mID;
DataKind(int id) {
@@ -382,6 +383,41 @@ public class Element extends BaseObj {
return rs.mElement_FLOAT_4;
}
+ public static Element F64_2(RenderScript rs) {
+ if(rs.mElement_DOUBLE_2 == null) {
+ rs.mElement_DOUBLE_2 = createVector(rs, DataType.FLOAT_64, 2);
+ }
+ return rs.mElement_DOUBLE_2;
+ }
+
+ public static Element F64_3(RenderScript rs) {
+ if(rs.mElement_DOUBLE_3 == null) {
+ rs.mElement_DOUBLE_3 = createVector(rs, DataType.FLOAT_64, 3);
+ }
+ return rs.mElement_DOUBLE_3;
+ }
+
+ public static Element F64_4(RenderScript rs) {
+ if(rs.mElement_DOUBLE_4 == null) {
+ rs.mElement_DOUBLE_4 = createVector(rs, DataType.FLOAT_64, 4);
+ }
+ return rs.mElement_DOUBLE_4;
+ }
+
+ public static Element U8_2(RenderScript rs) {
+ if(rs.mElement_UCHAR_2 == null) {
+ rs.mElement_UCHAR_2 = createVector(rs, DataType.UNSIGNED_8, 2);
+ }
+ return rs.mElement_UCHAR_2;
+ }
+
+ public static Element U8_3(RenderScript rs) {
+ if(rs.mElement_UCHAR_3 == null) {
+ rs.mElement_UCHAR_3 = createVector(rs, DataType.UNSIGNED_8, 3);
+ }
+ return rs.mElement_UCHAR_3;
+ }
+
public static Element U8_4(RenderScript rs) {
if(rs.mElement_UCHAR_4 == null) {
rs.mElement_UCHAR_4 = createVector(rs, DataType.UNSIGNED_8, 4);
@@ -389,6 +425,153 @@ public class Element extends BaseObj {
return rs.mElement_UCHAR_4;
}
+ public static Element I8_2(RenderScript rs) {
+ if(rs.mElement_CHAR_2 == null) {
+ rs.mElement_CHAR_2 = createVector(rs, DataType.SIGNED_8, 2);
+ }
+ return rs.mElement_CHAR_2;
+ }
+
+ public static Element I8_3(RenderScript rs) {
+ if(rs.mElement_CHAR_3 == null) {
+ rs.mElement_CHAR_3 = createVector(rs, DataType.SIGNED_8, 3);
+ }
+ return rs.mElement_CHAR_3;
+ }
+
+ public static Element I8_4(RenderScript rs) {
+ if(rs.mElement_CHAR_4 == null) {
+ rs.mElement_CHAR_4 = createVector(rs, DataType.SIGNED_8, 4);
+ }
+ return rs.mElement_CHAR_4;
+ }
+
+ public static Element U16_2(RenderScript rs) {
+ if(rs.mElement_USHORT_2 == null) {
+ rs.mElement_USHORT_2 = createVector(rs, DataType.UNSIGNED_16, 2);
+ }
+ return rs.mElement_USHORT_2;
+ }
+
+ public static Element U16_3(RenderScript rs) {
+ if(rs.mElement_USHORT_3 == null) {
+ rs.mElement_USHORT_3 = createVector(rs, DataType.UNSIGNED_16, 3);
+ }
+ return rs.mElement_USHORT_3;
+ }
+
+ public static Element U16_4(RenderScript rs) {
+ if(rs.mElement_USHORT_4 == null) {
+ rs.mElement_USHORT_4 = createVector(rs, DataType.UNSIGNED_16, 4);
+ }
+ return rs.mElement_USHORT_4;
+ }
+
+ public static Element I16_2(RenderScript rs) {
+ if(rs.mElement_SHORT_2 == null) {
+ rs.mElement_SHORT_2 = createVector(rs, DataType.SIGNED_16, 2);
+ }
+ return rs.mElement_SHORT_2;
+ }
+
+ public static Element I16_3(RenderScript rs) {
+ if(rs.mElement_SHORT_3 == null) {
+ rs.mElement_SHORT_3 = createVector(rs, DataType.SIGNED_16, 3);
+ }
+ return rs.mElement_SHORT_3;
+ }
+
+ public static Element I16_4(RenderScript rs) {
+ if(rs.mElement_SHORT_4 == null) {
+ rs.mElement_SHORT_4 = createVector(rs, DataType.SIGNED_16, 4);
+ }
+ return rs.mElement_SHORT_4;
+ }
+
+ public static Element U32_2(RenderScript rs) {
+ if(rs.mElement_UINT_2 == null) {
+ rs.mElement_UINT_2 = createVector(rs, DataType.UNSIGNED_32, 2);
+ }
+ return rs.mElement_UINT_2;
+ }
+
+ public static Element U32_3(RenderScript rs) {
+ if(rs.mElement_UINT_3 == null) {
+ rs.mElement_UINT_3 = createVector(rs, DataType.UNSIGNED_32, 3);
+ }
+ return rs.mElement_UINT_3;
+ }
+
+ public static Element U32_4(RenderScript rs) {
+ if(rs.mElement_UINT_4 == null) {
+ rs.mElement_UINT_4 = createVector(rs, DataType.UNSIGNED_32, 4);
+ }
+ return rs.mElement_UINT_4;
+ }
+
+ public static Element I32_2(RenderScript rs) {
+ if(rs.mElement_INT_2 == null) {
+ rs.mElement_INT_2 = createVector(rs, DataType.SIGNED_32, 2);
+ }
+ return rs.mElement_INT_2;
+ }
+
+ public static Element I32_3(RenderScript rs) {
+ if(rs.mElement_INT_3 == null) {
+ rs.mElement_INT_3 = createVector(rs, DataType.SIGNED_32, 3);
+ }
+ return rs.mElement_INT_3;
+ }
+
+ public static Element I32_4(RenderScript rs) {
+ if(rs.mElement_INT_4 == null) {
+ rs.mElement_INT_4 = createVector(rs, DataType.SIGNED_32, 4);
+ }
+ return rs.mElement_INT_4;
+ }
+
+ public static Element U64_2(RenderScript rs) {
+ if(rs.mElement_ULONG_2 == null) {
+ rs.mElement_ULONG_2 = createVector(rs, DataType.UNSIGNED_64, 2);
+ }
+ return rs.mElement_ULONG_2;
+ }
+
+ public static Element U64_3(RenderScript rs) {
+ if(rs.mElement_ULONG_3 == null) {
+ rs.mElement_ULONG_3 = createVector(rs, DataType.UNSIGNED_64, 3);
+ }
+ return rs.mElement_ULONG_3;
+ }
+
+ public static Element U64_4(RenderScript rs) {
+ if(rs.mElement_ULONG_4 == null) {
+ rs.mElement_ULONG_4 = createVector(rs, DataType.UNSIGNED_64, 4);
+ }
+ return rs.mElement_ULONG_4;
+ }
+
+ public static Element I64_2(RenderScript rs) {
+ if(rs.mElement_LONG_2 == null) {
+ rs.mElement_LONG_2 = createVector(rs, DataType.SIGNED_64, 2);
+ }
+ return rs.mElement_LONG_2;
+ }
+
+ public static Element I64_3(RenderScript rs) {
+ if(rs.mElement_LONG_3 == null) {
+ rs.mElement_LONG_3 = createVector(rs, DataType.SIGNED_64, 3);
+ }
+ return rs.mElement_LONG_3;
+ }
+
+ public static Element I64_4(RenderScript rs) {
+ if(rs.mElement_LONG_4 == null) {
+ rs.mElement_LONG_4 = createVector(rs, DataType.SIGNED_64, 4);
+ }
+ return rs.mElement_LONG_4;
+ }
+
public static Element MATRIX_4X4(RenderScript rs) {
if(rs.mElement_MATRIX_4X4 == null) {
rs.mElement_MATRIX_4X4 = createUser(rs, DataType.MATRIX_4X4);
@@ -536,10 +719,12 @@ public class Element extends BaseObj {
dk == DataKind.PIXEL_A ||
dk == DataKind.PIXEL_LA ||
dk == DataKind.PIXEL_RGB ||
- dk == DataKind.PIXEL_RGBA)) {
+ dk == DataKind.PIXEL_RGBA ||
+ dk == DataKind.PIXEL_DEPTH)) {
throw new RSIllegalArgumentException("Unsupported DataKind");
}
if (!(dt == DataType.UNSIGNED_8 ||
+ dt == DataType.UNSIGNED_16 ||
dt == DataType.UNSIGNED_5_6_5 ||
dt == DataType.UNSIGNED_4_4_4_4 ||
dt == DataType.UNSIGNED_5_5_5_1)) {
@@ -554,16 +739,25 @@ public class Element extends BaseObj {
if (dt == DataType.UNSIGNED_4_4_4_4 && dk != DataKind.PIXEL_RGBA) {
throw new RSIllegalArgumentException("Bad kind and type combo");
}
+ if (dt == DataType.UNSIGNED_16 &&
+ dk != DataKind.PIXEL_DEPTH) {
+ throw new RSIllegalArgumentException("Bad kind and type combo");
+ }
int size = 1;
- if (dk == DataKind.PIXEL_LA) {
+ switch (dk) {
+ case PIXEL_LA:
size = 2;
- }
- if (dk == DataKind.PIXEL_RGB) {
+ break;
+ case PIXEL_RGB:
size = 3;
- }
- if (dk == DataKind.PIXEL_RGBA) {
+ break;
+ case PIXEL_RGBA:
size = 4;
+ break;
+ case PIXEL_DEPTH:
+ size = 2;
+ break;
}
boolean norm = true;
@@ -572,6 +766,33 @@ public class Element extends BaseObj {
}
/**
+ * Check if the current Element is compatible with another Element.
+ * Primitive Elements are compatible if they share the same underlying
+ * size and type (i.e. U8 is compatible with A_8). User-defined Elements
+ * must be equal in order to be compatible. This requires strict name
+ * equivalence for all sub-Elements (in addition to structural equivalence).
+ *
+ * @param e The Element to check compatibility with.
+ *
+ * @return boolean true if the Elements are compatible, otherwise false.
+ */
+ public boolean isCompatible(Element e) {
+ // Try strict BaseObj equality to start with.
+ if (this.equals(e)) {
+ return true;
+ }
+
+ // 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.
+ return ((mSize == e.mSize) &&
+ (mType != null) &&
+ (mType == e.mType) &&
+ (mVectorSize == e.mVectorSize));
+ }
+
+ /**
* Builder class for producing complex elements with matching field and name
* pairs. The builder starts empty. The order in which elements are added
* is retained for the layout in memory.
diff --git a/graphics/java/android/renderscript/FieldPacker.java b/graphics/java/android/renderscript/FieldPacker.java
index bdda830..2739a4b8 100644
--- a/graphics/java/android/renderscript/FieldPacker.java
+++ b/graphics/java/android/renderscript/FieldPacker.java
@@ -25,10 +25,15 @@ package android.renderscript;
public class FieldPacker {
public FieldPacker(int len) {
mPos = 0;
+ mLen = len;
mData = new byte[len];
}
public void align(int v) {
+ if ((v <= 0) || ((v & (v - 1)) != 0)) {
+ throw new RSIllegalArgumentException("argument must be a non-negative non-zero power of 2: " + v);
+ }
+
while ((mPos & (v - 1)) != 0) {
mData[mPos++] = 0;
}
@@ -38,11 +43,18 @@ public class FieldPacker {
mPos = 0;
}
public void reset(int i) {
+ if ((i < 0) || (i >= mLen)) {
+ throw new RSIllegalArgumentException("out of range argument: " + i);
+ }
mPos = i;
}
public void skip(int i) {
- mPos += i;
+ int res = mPos + i;
+ if ((res < 0) || (res > mLen)) {
+ throw new RSIllegalArgumentException("out of range argument: " + i);
+ }
+ mPos = res;
}
public void addI8(byte v) {
@@ -153,6 +165,22 @@ public class FieldPacker {
addF32(v.w);
}
+ public void addF64(Double2 v) {
+ addF64(v.x);
+ addF64(v.y);
+ }
+ public void addF64(Double3 v) {
+ addF64(v.x);
+ addF64(v.y);
+ addF64(v.z);
+ }
+ public void addF64(Double4 v) {
+ addF64(v.x);
+ addF64(v.y);
+ addF64(v.z);
+ addF64(v.w);
+ }
+
public void addI8(Byte2 v) {
addI8(v.x);
addI8(v.y);
@@ -249,6 +277,38 @@ public class FieldPacker {
addU32(v.w);
}
+ public void addI64(Long2 v) {
+ addI64(v.x);
+ addI64(v.y);
+ }
+ public void addI64(Long3 v) {
+ addI64(v.x);
+ addI64(v.y);
+ addI64(v.z);
+ }
+ public void addI64(Long4 v) {
+ addI64(v.x);
+ addI64(v.y);
+ addI64(v.z);
+ addI64(v.w);
+ }
+
+ public void addU64(Long2 v) {
+ addU64(v.x);
+ addU64(v.y);
+ }
+ public void addU64(Long3 v) {
+ addU64(v.x);
+ addU64(v.y);
+ addU64(v.z);
+ }
+ public void addU64(Long4 v) {
+ addU64(v.x);
+ addU64(v.y);
+ addU64(v.z);
+ addU64(v.w);
+ }
+
public void addMatrix(Matrix4f v) {
for (int i=0; i < v.mMat.length; i++) {
addF32(v.mMat[i]);
@@ -277,6 +337,7 @@ public class FieldPacker {
private final byte mData[];
private int mPos;
+ private int mLen;
}
diff --git a/graphics/java/android/renderscript/Font.java b/graphics/java/android/renderscript/Font.java
index fa27590..18dacac 100644
--- a/graphics/java/android/renderscript/Font.java
+++ b/graphics/java/android/renderscript/Font.java
@@ -89,10 +89,10 @@ public class Font extends BaseObj {
FontFamily sansFamily = new FontFamily();
sansFamily.mNames = sSansNames;
- sansFamily.mNormalFileName = "DroidSans.ttf";
- sansFamily.mBoldFileName = "DroidSans-Bold.ttf";
- sansFamily.mItalicFileName = "DroidSans.ttf";
- sansFamily.mBoldItalicFileName = "DroidSans-Bold.ttf";
+ sansFamily.mNormalFileName = "Roboto-Regular.ttf";
+ sansFamily.mBoldFileName = "Roboto-Bold.ttf";
+ sansFamily.mItalicFileName = "Roboto-Italic.ttf";
+ sansFamily.mBoldItalicFileName = "Roboto-BoldItalic.ttf";
addFamilyToMap(sansFamily);
FontFamily serifFamily = new FontFamily();
@@ -201,12 +201,14 @@ public class Font extends BaseObj {
/**
* Accepts one of the following family names as an argument
- * and will attemp to produce the best match with a system font
+ * and will attempt to produce the best match with a system font:
+ *
* "sans-serif" "arial" "helvetica" "tahoma" "verdana"
* "serif" "times" "times new roman" "palatino" "georgia" "baskerville"
* "goudy" "fantasy" "cursive" "ITC Stone Serif"
* "monospace" "courier" "courier new" "monaco"
- * Returns default font if no match could be found
+ *
+ * Returns default font if no match could be found.
*/
static public Font create(RenderScript rs, Resources res, String familyName, Style fontStyle, float pointSize) {
String fileName = getFontFileName(familyName, fontStyle);
diff --git a/graphics/java/android/renderscript/Int2.java b/graphics/java/android/renderscript/Int2.java
index 7aaa4e8..434af21 100644
--- a/graphics/java/android/renderscript/Int2.java
+++ b/graphics/java/android/renderscript/Int2.java
@@ -28,6 +28,11 @@ public class Int2 {
public Int2() {
}
+ public Int2(int initX, int initY) {
+ x = initX;
+ y = initY;
+ }
+
public int x;
public int y;
}
diff --git a/graphics/java/android/renderscript/Int3.java b/graphics/java/android/renderscript/Int3.java
index e5c1cdf..333ccf8 100644
--- a/graphics/java/android/renderscript/Int3.java
+++ b/graphics/java/android/renderscript/Int3.java
@@ -28,6 +28,12 @@ public class Int3 {
public Int3() {
}
+ public Int3(int initX, int initY, int initZ) {
+ x = initX;
+ y = initY;
+ z = initZ;
+ }
+
public int x;
public int y;
public int z;
diff --git a/graphics/java/android/renderscript/Int4.java b/graphics/java/android/renderscript/Int4.java
index 5289a89..8734c95 100644
--- a/graphics/java/android/renderscript/Int4.java
+++ b/graphics/java/android/renderscript/Int4.java
@@ -28,6 +28,13 @@ public class Int4 {
public Int4() {
}
+ public Int4(int initX, int initY, int initZ, int initW) {
+ x = initX;
+ y = initY;
+ z = initZ;
+ w = initW;
+ }
+
public int x;
public int y;
public int z;
diff --git a/graphics/java/android/renderscript/Long2.java b/graphics/java/android/renderscript/Long2.java
index 8590b96..95ea18c 100644
--- a/graphics/java/android/renderscript/Long2.java
+++ b/graphics/java/android/renderscript/Long2.java
@@ -27,6 +27,11 @@ public class Long2 {
public Long2() {
}
+ public Long2(long initX, long initY) {
+ x = initX;
+ y = initY;
+ }
+
public long x;
public long y;
}
diff --git a/graphics/java/android/renderscript/Long3.java b/graphics/java/android/renderscript/Long3.java
index 6ae837a..96ee885 100644
--- a/graphics/java/android/renderscript/Long3.java
+++ b/graphics/java/android/renderscript/Long3.java
@@ -27,6 +27,12 @@ public class Long3 {
public Long3() {
}
+ public Long3(long initX, long initY, long initZ) {
+ x = initX;
+ y = initY;
+ z = initZ;
+ }
+
public long x;
public long y;
public long z;
diff --git a/graphics/java/android/renderscript/Long4.java b/graphics/java/android/renderscript/Long4.java
index 04c12f2..50e664c 100644
--- a/graphics/java/android/renderscript/Long4.java
+++ b/graphics/java/android/renderscript/Long4.java
@@ -27,6 +27,13 @@ public class Long4 {
public Long4() {
}
+ public Long4(long initX, long initY, long initZ, long initW) {
+ x = initX;
+ y = initY;
+ z = initZ;
+ w = initW;
+ }
+
public long x;
public long y;
public long z;
diff --git a/graphics/java/android/renderscript/Mesh.java b/graphics/java/android/renderscript/Mesh.java
index bb910cc..7b3b73f 100644
--- a/graphics/java/android/renderscript/Mesh.java
+++ b/graphics/java/android/renderscript/Mesh.java
@@ -18,7 +18,6 @@ package android.renderscript;
import java.util.Vector;
-import android.util.Config;
import android.util.Log;
/**
@@ -321,53 +320,55 @@ public class Mesh extends BaseObj {
return tb.create();
}
- static synchronized Mesh internalCreate(RenderScript rs, Builder b) {
+ /**
+ * Create a Mesh object from the current state of the builder
+ *
+ **/
+ public Mesh create() {
+ mRS.validate();
+ int[] vtx = new int[mVertexTypeCount];
+ int[] idx = new int[mIndexTypes.size()];
+ int[] prim = new int[mIndexTypes.size()];
- int id = rs.nMeshCreate(b.mVertexTypeCount, b.mIndexTypes.size());
- Mesh newMesh = new Mesh(id, rs);
- newMesh.mIndexBuffers = new Allocation[b.mIndexTypes.size()];
- newMesh.mPrimitives = new Primitive[b.mIndexTypes.size()];
- newMesh.mVertexBuffers = new Allocation[b.mVertexTypeCount];
+ Allocation[] vertexBuffers = new Allocation[mVertexTypeCount];
+ Allocation[] indexBuffers = new Allocation[mIndexTypes.size()];
+ Primitive[] primitives = new Primitive[mIndexTypes.size()];
- for(int ct = 0; ct < b.mIndexTypes.size(); ct ++) {
+ for(int ct = 0; ct < mVertexTypeCount; ct ++) {
Allocation alloc = null;
- Entry entry = (Entry)b.mIndexTypes.elementAt(ct);
+ Entry entry = mVertexTypes[ct];
if (entry.t != null) {
- alloc = Allocation.createTyped(rs, entry.t, b.mUsage);
- }
- else if(entry.e != null) {
- alloc = Allocation.createSized(rs, entry.e, entry.size, b.mUsage);
+ alloc = Allocation.createTyped(mRS, entry.t, mUsage);
+ } else if(entry.e != null) {
+ alloc = Allocation.createSized(mRS, entry.e, entry.size, mUsage);
}
- int allocID = (alloc == null) ? 0 : alloc.getID();
- rs.nMeshBindIndex(id, allocID, entry.prim.mID, ct);
- newMesh.mIndexBuffers[ct] = alloc;
- newMesh.mPrimitives[ct] = entry.prim;
+ vertexBuffers[ct] = alloc;
+ vtx[ct] = alloc.getID();
}
- for(int ct = 0; ct < b.mVertexTypeCount; ct ++) {
+ for(int ct = 0; ct < mIndexTypes.size(); ct ++) {
Allocation alloc = null;
- Entry entry = b.mVertexTypes[ct];
+ Entry entry = (Entry)mIndexTypes.elementAt(ct);
if (entry.t != null) {
- alloc = Allocation.createTyped(rs, entry.t, b.mUsage);
+ alloc = Allocation.createTyped(mRS, entry.t, mUsage);
} else if(entry.e != null) {
- alloc = Allocation.createSized(rs, entry.e, entry.size, b.mUsage);
+ alloc = Allocation.createSized(mRS, entry.e, entry.size, mUsage);
}
- rs.nMeshBindVertex(id, alloc.getID(), ct);
- newMesh.mVertexBuffers[ct] = alloc;
+ int allocID = (alloc == null) ? 0 : alloc.getID();
+ indexBuffers[ct] = alloc;
+ primitives[ct] = entry.prim;
+
+ idx[ct] = allocID;
+ prim[ct] = entry.prim.mID;
}
- rs.nMeshInitVertexAttribs(id);
- return newMesh;
- }
+ int id = mRS.nMeshCreate(vtx, idx, prim);
+ Mesh newMesh = new Mesh(id, mRS);
+ newMesh.mVertexBuffers = vertexBuffers;
+ newMesh.mIndexBuffers = indexBuffers;
+ newMesh.mPrimitives = primitives;
- /**
- * Create a Mesh object from the current state of the builder
- *
- **/
- public Mesh create() {
- mRS.validate();
- Mesh sm = internalCreate(mRS, this);
- return sm;
+ return newMesh;
}
}
@@ -464,40 +465,44 @@ public class Mesh extends BaseObj {
return this;
}
- static synchronized Mesh internalCreate(RenderScript rs, AllocationBuilder b) {
+ /**
+ * Create a Mesh object from the current state of the builder
+ *
+ **/
+ public Mesh create() {
+ mRS.validate();
- int id = rs.nMeshCreate(b.mVertexTypeCount, b.mIndexTypes.size());
- Mesh newMesh = new Mesh(id, rs);
- newMesh.mIndexBuffers = new Allocation[b.mIndexTypes.size()];
- newMesh.mPrimitives = new Primitive[b.mIndexTypes.size()];
- newMesh.mVertexBuffers = new Allocation[b.mVertexTypeCount];
+ int[] vtx = new int[mVertexTypeCount];
+ int[] idx = new int[mIndexTypes.size()];
+ int[] prim = new int[mIndexTypes.size()];
- for(int ct = 0; ct < b.mIndexTypes.size(); ct ++) {
- Entry entry = (Entry)b.mIndexTypes.elementAt(ct);
- int allocID = (entry.a == null) ? 0 : entry.a.getID();
- rs.nMeshBindIndex(id, allocID, entry.prim.mID, ct);
- newMesh.mIndexBuffers[ct] = entry.a;
- newMesh.mPrimitives[ct] = entry.prim;
+ Allocation[] indexBuffers = new Allocation[mIndexTypes.size()];
+ Primitive[] primitives = new Primitive[mIndexTypes.size()];
+ Allocation[] vertexBuffers = new Allocation[mVertexTypeCount];
+
+ for(int ct = 0; ct < mVertexTypeCount; ct ++) {
+ Entry entry = mVertexTypes[ct];
+ vertexBuffers[ct] = entry.a;
+ vtx[ct] = entry.a.getID();
}
- for(int ct = 0; ct < b.mVertexTypeCount; ct ++) {
- Entry entry = b.mVertexTypes[ct];
- rs.nMeshBindVertex(id, entry.a.getID(), ct);
- newMesh.mVertexBuffers[ct] = entry.a;
+ for(int ct = 0; ct < mIndexTypes.size(); ct ++) {
+ Entry entry = (Entry)mIndexTypes.elementAt(ct);
+ int allocID = (entry.a == null) ? 0 : entry.a.getID();
+ indexBuffers[ct] = entry.a;
+ primitives[ct] = entry.prim;
+
+ idx[ct] = allocID;
+ prim[ct] = entry.prim.mID;
}
- rs.nMeshInitVertexAttribs(id);
- return newMesh;
- }
+ int id = mRS.nMeshCreate(vtx, idx, prim);
+ Mesh newMesh = new Mesh(id, mRS);
+ newMesh.mVertexBuffers = vertexBuffers;
+ newMesh.mIndexBuffers = indexBuffers;
+ newMesh.mPrimitives = primitives;
- /**
- * Create a Mesh object from the current state of the builder
- *
- **/
- public Mesh create() {
- mRS.validate();
- Mesh sm = internalCreate(mRS, this);
- return sm;
+ return newMesh;
}
}
diff --git a/graphics/java/android/renderscript/Program.java b/graphics/java/android/renderscript/Program.java
index 323225f..a1b1ba3 100644
--- a/graphics/java/android/renderscript/Program.java
+++ b/graphics/java/android/renderscript/Program.java
@@ -22,7 +22,6 @@ import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import android.content.res.Resources;
-import android.util.Config;
import android.util.Log;
diff --git a/graphics/java/android/renderscript/ProgramFragment.java b/graphics/java/android/renderscript/ProgramFragment.java
index a48c2e3..21bace8 100644
--- a/graphics/java/android/renderscript/ProgramFragment.java
+++ b/graphics/java/android/renderscript/ProgramFragment.java
@@ -17,7 +17,6 @@
package android.renderscript;
-import android.util.Config;
import android.util.Log;
diff --git a/graphics/java/android/renderscript/ProgramFragmentFixedFunction.java b/graphics/java/android/renderscript/ProgramFragmentFixedFunction.java
index f99cd7b..0ab73c1 100644
--- a/graphics/java/android/renderscript/ProgramFragmentFixedFunction.java
+++ b/graphics/java/android/renderscript/ProgramFragmentFixedFunction.java
@@ -17,7 +17,6 @@
package android.renderscript;
-import android.util.Config;
import android.util.Log;
diff --git a/graphics/java/android/renderscript/ProgramRaster.java b/graphics/java/android/renderscript/ProgramRaster.java
index b89d36d..bc0d928 100644
--- a/graphics/java/android/renderscript/ProgramRaster.java
+++ b/graphics/java/android/renderscript/ProgramRaster.java
@@ -17,7 +17,6 @@
package android.renderscript;
-import android.util.Config;
import android.util.Log;
@@ -55,18 +54,6 @@ public class ProgramRaster extends BaseObj {
mCullMode = CullMode.BACK;
}
- void setLineWidth(float w) {
- mRS.validate();
- mLineWidth = w;
- mRS.nProgramRasterSetLineWidth(getID(), w);
- }
-
- void setCullMode(CullMode m) {
- mRS.validate();
- mCullMode = m;
- mRS.nProgramRasterSetCullMode(getID(), m.mID);
- }
-
public static ProgramRaster CULL_BACK(RenderScript rs) {
if(rs.mProgramRaster_CULL_BACK == null) {
ProgramRaster.Builder builder = new ProgramRaster.Builder(rs);
@@ -119,16 +106,11 @@ public class ProgramRaster extends BaseObj {
return this;
}
- static synchronized ProgramRaster internalCreate(RenderScript rs, Builder b) {
- int id = rs.nProgramRasterCreate(b.mPointSmooth, b.mLineSmooth, b.mPointSprite);
- ProgramRaster pr = new ProgramRaster(id, rs);
- pr.setCullMode(b.mCullMode);
- return pr;
- }
-
public ProgramRaster create() {
mRS.validate();
- return internalCreate(mRS, this);
+ int id = mRS.nProgramRasterCreate(mPointSmooth, mLineSmooth, mPointSprite,
+ 1.f, mCullMode.mID);
+ return new ProgramRaster(id, mRS);
}
}
diff --git a/graphics/java/android/renderscript/ProgramStore.java b/graphics/java/android/renderscript/ProgramStore.java
index c46e6b9..fb7c8ca 100644
--- a/graphics/java/android/renderscript/ProgramStore.java
+++ b/graphics/java/android/renderscript/ProgramStore.java
@@ -17,7 +17,6 @@
package android.renderscript;
-import android.util.Config;
import android.util.Log;
@@ -333,27 +332,15 @@ public class ProgramStore extends BaseObj {
return this;
}
- static synchronized ProgramStore internalCreate(RenderScript rs, Builder b) {
- rs.nProgramStoreBegin(0, 0);
- rs.nProgramStoreDepthFunc(b.mDepthFunc.mID);
- rs.nProgramStoreDepthMask(b.mDepthMask);
- rs.nProgramStoreColorMask(b.mColorMaskR,
- b.mColorMaskG,
- b.mColorMaskB,
- b.mColorMaskA);
- rs.nProgramStoreBlendFunc(b.mBlendSrc.mID, b.mBlendDst.mID);
- rs.nProgramStoreDither(b.mDither);
-
- int id = rs.nProgramStoreCreate();
- return new ProgramStore(id, rs);
- }
-
/**
* Creates a program store from the current state of the builder
*/
public ProgramStore create() {
mRS.validate();
- return internalCreate(mRS, this);
+ int id = mRS.nProgramStoreCreate(mColorMaskR, mColorMaskG, mColorMaskB, mColorMaskA,
+ mDepthMask, mDither,
+ mBlendSrc.mID, mBlendDst.mID, mDepthFunc.mID);
+ return new ProgramStore(id, mRS);
}
}
diff --git a/graphics/java/android/renderscript/ProgramVertex.java b/graphics/java/android/renderscript/ProgramVertex.java
index 55653f7..56bb836 100644
--- a/graphics/java/android/renderscript/ProgramVertex.java
+++ b/graphics/java/android/renderscript/ProgramVertex.java
@@ -39,7 +39,6 @@ package android.renderscript;
import android.graphics.Matrix;
-import android.util.Config;
import android.util.Log;
diff --git a/graphics/java/android/renderscript/ProgramVertexFixedFunction.java b/graphics/java/android/renderscript/ProgramVertexFixedFunction.java
index 556964a..740d6a5 100644
--- a/graphics/java/android/renderscript/ProgramVertexFixedFunction.java
+++ b/graphics/java/android/renderscript/ProgramVertexFixedFunction.java
@@ -18,7 +18,6 @@ package android.renderscript;
import android.graphics.Matrix;
-import android.util.Config;
import android.util.Log;
diff --git a/graphics/java/android/renderscript/RSTextureView.java b/graphics/java/android/renderscript/RSTextureView.java
new file mode 100644
index 0000000..30b2f99
--- /dev/null
+++ b/graphics/java/android/renderscript/RSTextureView.java
@@ -0,0 +1,179 @@
+/*
+ * Copyright (C) 2011 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.io.Writer;
+import java.util.ArrayList;
+import java.util.concurrent.Semaphore;
+
+import android.content.Context;
+import android.graphics.SurfaceTexture;
+import android.os.Handler;
+import android.os.Message;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.view.TextureView;
+
+/**
+ * The Texture View for a graphics renderscript (RenderScriptGL)
+ * to draw on.
+ *
+ */
+public class RSTextureView extends TextureView implements TextureView.SurfaceTextureListener {
+ private RenderScriptGL mRS;
+ private SurfaceTexture mSurfaceTexture;
+
+ /**
+ * Standard View constructor. In order to render something, you
+ * must call {@link android.opengl.GLSurfaceView#setRenderer} to
+ * register a renderer.
+ */
+ public RSTextureView(Context context) {
+ super(context);
+ init();
+ //Log.v(RenderScript.LOG_TAG, "RSSurfaceView");
+ }
+
+ /**
+ * Standard View constructor. In order to render something, you
+ * must call {@link android.opengl.GLSurfaceView#setRenderer} to
+ * register a renderer.
+ */
+ public RSTextureView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ init();
+ //Log.v(RenderScript.LOG_TAG, "RSSurfaceView");
+ }
+
+ private void init() {
+ setSurfaceTextureListener(this);
+ //android.util.Log.e("rs", "getSurfaceTextureListerner " + getSurfaceTextureListener());
+ }
+
+ @Override
+ public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
+ //Log.e(RenderScript.LOG_TAG, "onSurfaceTextureAvailable");
+ mSurfaceTexture = surface;
+
+ if (mRS != null) {
+ mRS.setSurfaceTexture(mSurfaceTexture, width, height);
+ }
+ }
+
+ @Override
+ public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
+ //Log.e(RenderScript.LOG_TAG, "onSurfaceTextureSizeChanged");
+ mSurfaceTexture = surface;
+
+ if (mRS != null) {
+ mRS.setSurfaceTexture(mSurfaceTexture, width, height);
+ }
+ }
+
+ @Override
+ public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
+ //Log.e(RenderScript.LOG_TAG, "onSurfaceTextureDestroyed");
+ mSurfaceTexture = surface;
+
+ if (mRS != null) {
+ mRS.setSurfaceTexture(null, 0, 0);
+ }
+
+ return true;
+ }
+
+ @Override
+ public void onSurfaceTextureUpdated(SurfaceTexture surface) {
+ //Log.e(RenderScript.LOG_TAG, "onSurfaceTextureUpdated");
+ mSurfaceTexture = surface;
+ }
+
+ /**
+ * Inform the view that the activity is paused. The owner of this view must
+ * call this method when the activity is paused. Calling this method will
+ * pause the rendering thread.
+ * Must not be called before a renderer has been set.
+ */
+ public void pause() {
+ if(mRS != null) {
+ mRS.pause();
+ }
+ }
+
+ /**
+ * Inform the view that the activity is resumed. The owner of this view must
+ * call this method when the activity is resumed. Calling this method will
+ * recreate the OpenGL display and resume the rendering
+ * thread.
+ * Must not be called before a renderer has been set.
+ */
+ public void resume() {
+ if(mRS != null) {
+ mRS.resume();
+ }
+ }
+
+ /**
+ * Create a new RenderScriptGL object and attach it to the
+ * TextureView if present.
+ *
+ *
+ * @param sc The RS surface config to create.
+ *
+ * @return RenderScriptGL The new object created.
+ */
+ public RenderScriptGL createRenderScriptGL(RenderScriptGL.SurfaceConfig sc) {
+ RenderScriptGL rs = new RenderScriptGL(this.getContext(), sc);
+ setRenderScriptGL(rs);
+ if (mSurfaceTexture != null) {
+ mRS.setSurfaceTexture(mSurfaceTexture, getWidth(), getHeight());
+ }
+ return rs;
+ }
+
+ /**
+ * Destroy the RenderScriptGL object associated with this
+ * TextureView.
+ */
+ public void destroyRenderScriptGL() {
+ mRS.destroy();
+ mRS = null;
+ }
+
+ /**
+ * Set a new RenderScriptGL object. This also will attach the
+ * new object to the TextureView if present.
+ *
+ * @param rs The new RS object.
+ */
+ public void setRenderScriptGL(RenderScriptGL rs) {
+ mRS = rs;
+ if (mSurfaceTexture != null) {
+ mRS.setSurfaceTexture(mSurfaceTexture, getWidth(), getHeight());
+ }
+ }
+
+ /**
+ * Returns the previously set RenderScriptGL object.
+ *
+ * @return RenderScriptGL
+ */
+ public RenderScriptGL getRenderScriptGL() {
+ return mRS;
+ }
+}
+
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java
index b51279a..571b895 100644
--- a/graphics/java/android/renderscript/RenderScript.java
+++ b/graphics/java/android/renderscript/RenderScript.java
@@ -19,14 +19,18 @@ package android.renderscript;
import java.lang.reflect.Field;
import android.content.Context;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
-import android.util.Config;
+import android.graphics.SurfaceTexture;
+import android.os.Process;
import android.util.Log;
import android.view.Surface;
+
/**
* RenderScript base master class. An instance of this class creates native
* worker threads for processing commands from this object. This base class
@@ -40,7 +44,7 @@ public class RenderScript {
static final String LOG_TAG = "RenderScript_jni";
static final boolean DEBUG = false;
@SuppressWarnings({"UnusedDeclaration", "deprecation"})
- static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV;
+ static final boolean LOG_ENABLED = false;
private Context mApplicationContext;
@@ -69,35 +73,35 @@ public class RenderScript {
native int nDeviceCreate();
native void nDeviceDestroy(int dev);
native void nDeviceSetConfig(int dev, int param, int value);
- native void nContextGetUserMessage(int con, int[] data);
+ native int nContextGetUserMessage(int con, int[] data);
native String nContextGetErrorMessage(int con);
- native int nContextPeekMessage(int con, int[] subID, boolean wait);
+ native int nContextPeekMessage(int con, int[] subID);
native void nContextInitToClient(int con);
native void nContextDeinitToClient(int con);
// Methods below are wrapped to protect the non-threadsafe
// lockless fifo.
- native int rsnContextCreateGL(int dev, int ver,
+ native int rsnContextCreateGL(int dev, int ver, int sdkVer,
int colorMin, int colorPref,
int alphaMin, int alphaPref,
int depthMin, int depthPref,
int stencilMin, int stencilPref,
int samplesMin, int samplesPref, float samplesQ, int dpi);
- synchronized int nContextCreateGL(int dev, int ver,
+ synchronized int nContextCreateGL(int dev, int ver, int sdkVer,
int colorMin, int colorPref,
int alphaMin, int alphaPref,
int depthMin, int depthPref,
int stencilMin, int stencilPref,
int samplesMin, int samplesPref, float samplesQ, int dpi) {
- return rsnContextCreateGL(dev, ver, colorMin, colorPref,
+ return rsnContextCreateGL(dev, ver, sdkVer, colorMin, colorPref,
alphaMin, alphaPref, depthMin, depthPref,
stencilMin, stencilPref,
samplesMin, samplesPref, samplesQ, dpi);
}
- native int rsnContextCreate(int dev, int ver);
- synchronized int nContextCreate(int dev, int ver) {
- return rsnContextCreate(dev, ver);
+ native int rsnContextCreate(int dev, int ver, int sdkVer);
+ synchronized int nContextCreate(int dev, int ver, int sdkVer) {
+ return rsnContextCreate(dev, ver, sdkVer);
}
native void rsnContextDestroy(int con);
synchronized void nContextDestroy() {
@@ -109,6 +113,11 @@ public class RenderScript {
validate();
rsnContextSetSurface(mContext, w, h, sur);
}
+ native void rsnContextSetSurfaceTexture(int con, int w, int h, SurfaceTexture sur);
+ synchronized void nContextSetSurfaceTexture(int w, int h, SurfaceTexture sur) {
+ validate();
+ rsnContextSetSurfaceTexture(mContext, w, h, sur);
+ }
native void rsnContextSetPriority(int con, int p);
synchronized void nContextSetPriority(int p) {
validate();
@@ -295,6 +304,26 @@ public class RenderScript {
rsnAllocationElementData1D(mContext, id, xoff, mip, compIdx, d, sizeBytes);
}
+ native void rsnAllocationData2D(int con,
+ int dstAlloc, int dstXoff, int dstYoff,
+ int dstMip, int dstFace,
+ int width, int height,
+ int srcAlloc, int srcXoff, int srcYoff,
+ int srcMip, int srcFace);
+ synchronized void nAllocationData2D(int dstAlloc, int dstXoff, int dstYoff,
+ int dstMip, int dstFace,
+ int width, int height,
+ int srcAlloc, int srcXoff, int srcYoff,
+ int srcMip, int srcFace) {
+ validate();
+ rsnAllocationData2D(mContext,
+ dstAlloc, dstXoff, dstYoff,
+ dstMip, dstFace,
+ width, height,
+ srcAlloc, srcXoff, srcYoff,
+ srcMip, srcFace);
+ }
+
native void rsnAllocationData2D(int con, int id, int xoff, int yoff, int mip, int face, int w, int h, byte[] d, int sizeBytes);
synchronized void nAllocationData2D(int id, int xoff, int yoff, int mip, int face, int w, int h, byte[] d, int sizeBytes) {
validate();
@@ -421,6 +450,16 @@ public class RenderScript {
validate();
rsnScriptInvoke(mContext, id, slot);
}
+ native void rsnScriptForEach(int con, int id, int slot, int ain, int aout, byte[] params);
+ native void rsnScriptForEach(int con, int id, int slot, int ain, int aout);
+ synchronized void nScriptForEach(int id, int slot, int ain, int aout, byte[] params) {
+ validate();
+ if (params == null) {
+ rsnScriptForEach(mContext, id, slot, ain, aout);
+ } else {
+ rsnScriptForEach(mContext, id, slot, ain, aout, params);
+ }
+ }
native void rsnScriptInvokeV(int con, int id, int slot, byte[] params);
synchronized void nScriptInvokeV(int id, int slot, byte[] params) {
validate();
@@ -457,93 +496,39 @@ public class RenderScript {
rsnScriptSetVarObj(mContext, id, slot, val);
}
- native void rsnScriptCBegin(int con);
- synchronized void nScriptCBegin() {
- validate();
- rsnScriptCBegin(mContext);
- }
- native void rsnScriptCSetScript(int con, byte[] script, int offset, int length);
- synchronized void nScriptCSetScript(byte[] script, int offset, int length) {
+ native int rsnScriptCCreate(int con, String resName, String cacheDir,
+ byte[] script, int length);
+ synchronized int nScriptCCreate(String resName, String cacheDir, byte[] script, int length) {
validate();
- rsnScriptCSetScript(mContext, script, offset, length);
- }
- native int rsnScriptCCreate(int con, String packageName, String resName, String cacheDir);
- synchronized int nScriptCCreate(String packageName, String resName, String cacheDir) {
- validate();
- return rsnScriptCCreate(mContext, packageName, resName, cacheDir);
+ return rsnScriptCCreate(mContext, resName, cacheDir, script, length);
}
- native void rsnSamplerBegin(int con);
- synchronized void nSamplerBegin() {
- validate();
- rsnSamplerBegin(mContext);
- }
- native void rsnSamplerSet(int con, int param, int value);
- synchronized void nSamplerSet(int param, int value) {
+ native int rsnSamplerCreate(int con, int magFilter, int minFilter,
+ int wrapS, int wrapT, int wrapR, float aniso);
+ synchronized int nSamplerCreate(int magFilter, int minFilter,
+ int wrapS, int wrapT, int wrapR, float aniso) {
validate();
- rsnSamplerSet(mContext, param, value);
- }
- native void rsnSamplerSet2(int con, int param, float value);
- synchronized void nSamplerSet2(int param, float value) {
- validate();
- rsnSamplerSet2(mContext, param, value);
- }
- native int rsnSamplerCreate(int con);
- synchronized int nSamplerCreate() {
- validate();
- return rsnSamplerCreate(mContext);
+ return rsnSamplerCreate(mContext, magFilter, minFilter, wrapS, wrapT, wrapR, aniso);
}
- native void rsnProgramStoreBegin(int con, int in, int out);
- synchronized void nProgramStoreBegin(int in, int out) {
- validate();
- rsnProgramStoreBegin(mContext, in, out);
- }
- native void rsnProgramStoreDepthFunc(int con, int func);
- synchronized void nProgramStoreDepthFunc(int func) {
- validate();
- rsnProgramStoreDepthFunc(mContext, func);
- }
- native void rsnProgramStoreDepthMask(int con, boolean enable);
- synchronized void nProgramStoreDepthMask(boolean enable) {
- validate();
- rsnProgramStoreDepthMask(mContext, enable);
- }
- native void rsnProgramStoreColorMask(int con, boolean r, boolean g, boolean b, boolean a);
- synchronized void nProgramStoreColorMask(boolean r, boolean g, boolean b, boolean a) {
- validate();
- rsnProgramStoreColorMask(mContext, r, g, b, a);
- }
- native void rsnProgramStoreBlendFunc(int con, int src, int dst);
- synchronized void nProgramStoreBlendFunc(int src, int dst) {
- validate();
- rsnProgramStoreBlendFunc(mContext, src, dst);
- }
- native void rsnProgramStoreDither(int con, boolean enable);
- synchronized void nProgramStoreDither(boolean enable) {
+ native int rsnProgramStoreCreate(int con, boolean r, boolean g, boolean b, boolean a,
+ boolean depthMask, boolean dither,
+ int srcMode, int dstMode, int depthFunc);
+ synchronized int nProgramStoreCreate(boolean r, boolean g, boolean b, boolean a,
+ boolean depthMask, boolean dither,
+ int srcMode, int dstMode, int depthFunc) {
validate();
- rsnProgramStoreDither(mContext, enable);
- }
- native int rsnProgramStoreCreate(int con);
- synchronized int nProgramStoreCreate() {
- validate();
- return rsnProgramStoreCreate(mContext);
+ return rsnProgramStoreCreate(mContext, r, g, b, a, depthMask, dither, srcMode,
+ dstMode, depthFunc);
}
- native int rsnProgramRasterCreate(int con, boolean pointSmooth, boolean lineSmooth, boolean pointSprite);
- synchronized int nProgramRasterCreate(boolean pointSmooth, boolean lineSmooth, boolean pointSprite) {
- validate();
- return rsnProgramRasterCreate(mContext, pointSmooth, lineSmooth, pointSprite);
- }
- native void rsnProgramRasterSetLineWidth(int con, int pr, float v);
- synchronized void nProgramRasterSetLineWidth(int pr, float v) {
+ native int rsnProgramRasterCreate(int con, boolean pointSmooth, boolean lineSmooth,
+ boolean pointSprite, float lineWidth, int cullMode);
+ synchronized int nProgramRasterCreate(boolean pointSmooth, boolean lineSmooth,
+ boolean pointSprite, float lineWidth, int cullMode) {
validate();
- rsnProgramRasterSetLineWidth(mContext, pr, v);
- }
- native void rsnProgramRasterSetCullMode(int con, int pr, int mode);
- synchronized void nProgramRasterSetCullMode(int pr, int mode) {
- validate();
- rsnProgramRasterSetCullMode(mContext, pr, mode);
+ return rsnProgramRasterCreate(mContext, pointSmooth, lineSmooth, pointSprite, lineWidth,
+ cullMode);
}
native void rsnProgramBindConstants(int con, int pv, int slot, int mID);
@@ -572,25 +557,10 @@ public class RenderScript {
return rsnProgramVertexCreate(mContext, shader, params);
}
- native int rsnMeshCreate(int con, int vtxCount, int indexCount);
- synchronized int nMeshCreate(int vtxCount, int indexCount) {
- validate();
- return rsnMeshCreate(mContext, vtxCount, indexCount);
- }
- native void rsnMeshBindVertex(int con, int id, int alloc, int slot);
- synchronized void nMeshBindVertex(int id, int alloc, int slot) {
- validate();
- rsnMeshBindVertex(mContext, id, alloc, slot);
- }
- native void rsnMeshBindIndex(int con, int id, int alloc, int prim, int slot);
- synchronized void nMeshBindIndex(int id, int alloc, int prim, int slot) {
+ native int rsnMeshCreate(int con, int[] vtx, int[] idx, int[] prim);
+ synchronized int nMeshCreate(int[] vtx, int[] idx, int[] prim) {
validate();
- rsnMeshBindIndex(mContext, id, alloc, prim, slot);
- }
- native void rsnMeshInitVertexAttribs(int con, int id);
- synchronized void nMeshInitVertexAttribs(int id) {
- validate();
- rsnMeshInitVertexAttribs(mContext, id);
+ return rsnMeshCreate(mContext, vtx, idx, prim);
}
native int rsnMeshGetVertexBufferCount(int con, int id);
synchronized int nMeshGetVertexBufferCount(int id) {
@@ -652,8 +622,43 @@ public class RenderScript {
Element mElement_FLOAT_2;
Element mElement_FLOAT_3;
Element mElement_FLOAT_4;
+
+ Element mElement_DOUBLE_2;
+ Element mElement_DOUBLE_3;
+ Element mElement_DOUBLE_4;
+
+ Element mElement_UCHAR_2;
+ Element mElement_UCHAR_3;
Element mElement_UCHAR_4;
+ Element mElement_CHAR_2;
+ Element mElement_CHAR_3;
+ Element mElement_CHAR_4;
+
+ Element mElement_USHORT_2;
+ Element mElement_USHORT_3;
+ Element mElement_USHORT_4;
+
+ Element mElement_SHORT_2;
+ Element mElement_SHORT_3;
+ Element mElement_SHORT_4;
+
+ Element mElement_UINT_2;
+ Element mElement_UINT_3;
+ Element mElement_UINT_4;
+
+ Element mElement_INT_2;
+ Element mElement_INT_3;
+ Element mElement_INT_4;
+
+ Element mElement_ULONG_2;
+ Element mElement_ULONG_3;
+ Element mElement_ULONG_4;
+
+ Element mElement_LONG_2;
+ Element mElement_LONG_3;
+ Element mElement_LONG_4;
+
Element mElement_MATRIX_4X4;
Element mElement_MATRIX_3X3;
Element mElement_MATRIX_2X2;
@@ -743,9 +748,8 @@ public class RenderScript {
* processes.
*/
public enum Priority {
- // Remap these numbers to opaque...
- LOW (5), //ANDROID_PRIORITY_BACKGROUND + 5
- NORMAL (-4); //ANDROID_PRIORITY_DISPLAY
+ LOW (Process.THREAD_PRIORITY_BACKGROUND + (5 * Process.THREAD_PRIORITY_LESS_FAVORABLE)),
+ NORMAL (Process.THREAD_PRIORITY_DISPLAY);
int mID;
Priority(int id) {
@@ -796,7 +800,7 @@ public class RenderScript {
mRS.nContextInitToClient(mRS.mContext);
while(mRun) {
rbuf[0] = 0;
- int msg = mRS.nContextPeekMessage(mRS.mContext, mAuxData, true);
+ int msg = mRS.nContextPeekMessage(mRS.mContext, mAuxData);
int size = mAuxData[1];
int subID = mAuxData[0];
@@ -804,7 +808,10 @@ public class RenderScript {
if ((size>>2) >= rbuf.length) {
rbuf = new int[(size + 3) >> 2];
}
- mRS.nContextGetUserMessage(mRS.mContext, rbuf);
+ if (mRS.nContextGetUserMessage(mRS.mContext, rbuf) !=
+ RS_MESSAGE_TO_CLIENT_USER) {
+ throw new RSDriverException("Error processing message from Renderscript.");
+ }
if(mRS.mMessageCallback != null) {
mRS.mMessageCallback.mData = rbuf;
@@ -860,6 +867,16 @@ public class RenderScript {
return mApplicationContext;
}
+ static int getTargetSdkVersion(Context ctx) {
+ try {
+ PackageManager pm = ctx.getPackageManager();
+ ApplicationInfo app = pm.getApplicationInfo(ctx.getPackageName(), 0);
+ return app.targetSdkVersion;
+ } catch (Exception e) {
+ throw new RSDriverException("Error calculating target SDK version for RS.");
+ }
+ }
+
/**
* Create a basic RenderScript context.
*
@@ -869,8 +886,13 @@ public class RenderScript {
public static RenderScript create(Context ctx) {
RenderScript rs = new RenderScript(ctx);
+ int sdkVersion = getTargetSdkVersion(ctx);
+
rs.mDev = rs.nDeviceCreate();
- rs.mContext = rs.nContextCreate(rs.mDev, 0);
+ rs.mContext = rs.nContextCreate(rs.mDev, 0, sdkVersion);
+ if (rs.mContext == 0) {
+ throw new RSDriverException("Failed to create RS context.");
+ }
rs.mMessageThread = new MessageThread(rs);
rs.mMessageThread.start();
return rs;
diff --git a/graphics/java/android/renderscript/RenderScriptGL.java b/graphics/java/android/renderscript/RenderScriptGL.java
index d4b5434..2dfcc83 100644
--- a/graphics/java/android/renderscript/RenderScriptGL.java
+++ b/graphics/java/android/renderscript/RenderScriptGL.java
@@ -22,7 +22,7 @@ import android.content.Context;
import android.graphics.PixelFormat;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
-import android.util.Config;
+import android.graphics.SurfaceTexture;
import android.util.Log;
import android.view.Surface;
import android.view.SurfaceHolder;
@@ -36,7 +36,6 @@ import android.view.SurfaceView;
* the screen.
**/
public class RenderScriptGL extends RenderScript {
- private Surface mSurface;
int mWidth;
int mHeight;
@@ -161,12 +160,13 @@ public class RenderScriptGL extends RenderScript {
super(ctx);
mSurfaceConfig = new SurfaceConfig(sc);
- mSurface = null;
+ int sdkVersion = getTargetSdkVersion(ctx);
+
mWidth = 0;
mHeight = 0;
mDev = nDeviceCreate();
int dpi = ctx.getResources().getDisplayMetrics().densityDpi;
- mContext = nContextCreateGL(mDev, 0,
+ mContext = nContextCreateGL(mDev, 0, sdkVersion,
mSurfaceConfig.mColorMin, mSurfaceConfig.mColorPref,
mSurfaceConfig.mAlphaMin, mSurfaceConfig.mAlphaPref,
mSurfaceConfig.mDepthMin, mSurfaceConfig.mDepthPref,
@@ -190,14 +190,29 @@ public class RenderScriptGL extends RenderScript {
*/
public void setSurface(SurfaceHolder sur, int w, int h) {
validate();
+ Surface s = null;
if (sur != null) {
- mSurface = sur.getSurface();
- } else {
- mSurface = null;
+ s = sur.getSurface();
}
mWidth = w;
mHeight = h;
- nContextSetSurface(w, h, mSurface);
+ nContextSetSurface(w, h, s);
+ }
+
+ /**
+ * Bind an os surface
+ *
+ * @param w
+ * @param h
+ * @param sur
+ */
+ public void setSurfaceTexture(SurfaceTexture sur, int w, int h) {
+ validate();
+ //android.util.Log.v("rs", "set surface " + sur + " w=" + w + ", h=" + h);
+
+ mWidth = w;
+ mHeight = h;
+ nContextSetSurfaceTexture(w, h, sur);
}
/**
diff --git a/graphics/java/android/renderscript/Sampler.java b/graphics/java/android/renderscript/Sampler.java
index 8ee4d72..98943a1 100644
--- a/graphics/java/android/renderscript/Sampler.java
+++ b/graphics/java/android/renderscript/Sampler.java
@@ -22,7 +22,6 @@ import java.io.InputStream;
import android.content.res.Resources;
import android.os.Bundle;
-import android.util.Config;
import android.util.Log;
import android.graphics.Bitmap;
@@ -240,21 +239,10 @@ public class Sampler extends BaseObj {
}
}
- static synchronized Sampler internalCreate(RenderScript rs, Builder b) {
- rs.nSamplerBegin();
- rs.nSamplerSet(0, b.mMin.mID);
- rs.nSamplerSet(1, b.mMag.mID);
- rs.nSamplerSet(2, b.mWrapS.mID);
- rs.nSamplerSet(3, b.mWrapT.mID);
- rs.nSamplerSet(4, b.mWrapR.mID);
- rs.nSamplerSet2(5, b.mAniso);
- int id = rs.nSamplerCreate();
- return new Sampler(id, rs);
- }
-
public Sampler create() {
mRS.validate();
- return internalCreate(mRS, this);
+ int id = mRS.nSamplerCreate(mMag.mID, mMin.mID, mWrapS.mID, mWrapT.mID, mWrapR.mID, mAniso);
+ return new Sampler(id, mRS);
}
}
diff --git a/graphics/java/android/renderscript/Script.java b/graphics/java/android/renderscript/Script.java
index 56abba5..d00c428 100644
--- a/graphics/java/android/renderscript/Script.java
+++ b/graphics/java/android/renderscript/Script.java
@@ -43,6 +43,34 @@ public class Script extends BaseObj {
}
}
+ /**
+ * Only intended for use by generated reflected code.
+ *
+ * @param slot
+ * @param ain
+ * @param aout
+ * @param v
+ */
+ protected void forEach(int slot, Allocation ain, Allocation aout, FieldPacker v) {
+ if (ain == null && aout == null) {
+ throw new RSIllegalArgumentException(
+ "At least one of ain or aout is required to be non-null.");
+ }
+ int in_id = 0;
+ if (ain != null) {
+ in_id = ain.getID();
+ }
+ int out_id = 0;
+ if (aout != null) {
+ out_id = aout.getID();
+ }
+ byte[] params = null;
+ if (v != null) {
+ params = v.getData();
+ }
+ mRS.nScriptForEach(getID(), slot, in_id, out_id, params);
+ }
+
Script(int id, RenderScript rs) {
super(id, rs);
diff --git a/graphics/java/android/renderscript/ScriptC.java b/graphics/java/android/renderscript/ScriptC.java
index 9445283..90f959f 100644
--- a/graphics/java/android/renderscript/ScriptC.java
+++ b/graphics/java/android/renderscript/ScriptC.java
@@ -92,16 +92,13 @@ public class ScriptC extends Script {
throw new Resources.NotFoundException();
}
- rs.nScriptCBegin();
- rs.nScriptCSetScript(pgm, 0, pgmLength);
-
// E.g, /system/apps/Fountain.apk
- String packageName = rs.getApplicationContext().getPackageResourcePath();
+ //String packageName = rs.getApplicationContext().getPackageResourcePath();
// For res/raw/fountain.bc, it wil be /com.android.fountain:raw/fountain
- String resName = resources.getResourceName(resourceID);
+ String resName = resources.getResourceEntryName(resourceID);
String cacheDir = rs.getApplicationContext().getCacheDir().toString();
Log.v(TAG, "Create script for resource = " + resName);
- return rs.nScriptCCreate(packageName, resName, cacheDir);
+ return rs.nScriptCCreate(resName, cacheDir, pgm, pgmLength);
}
}
diff --git a/graphics/java/android/renderscript/Short2.java b/graphics/java/android/renderscript/Short2.java
index 7094edd..617f1f5 100644
--- a/graphics/java/android/renderscript/Short2.java
+++ b/graphics/java/android/renderscript/Short2.java
@@ -28,6 +28,11 @@ public class Short2 {
public Short2() {
}
+ public Short2(short initX, short initY) {
+ x = initX;
+ y = initY;
+ }
+
public short x;
public short y;
}
diff --git a/graphics/java/android/renderscript/Short3.java b/graphics/java/android/renderscript/Short3.java
index f34500c..b9ca49b 100644
--- a/graphics/java/android/renderscript/Short3.java
+++ b/graphics/java/android/renderscript/Short3.java
@@ -28,6 +28,12 @@ public class Short3 {
public Short3() {
}
+ public Short3(short initX, short initY, short initZ) {
+ x = initX;
+ y = initY;
+ z = initZ;
+ }
+
public short x;
public short y;
public short z;
diff --git a/graphics/java/android/renderscript/Short4.java b/graphics/java/android/renderscript/Short4.java
index 5698fee..d5f2db5 100644
--- a/graphics/java/android/renderscript/Short4.java
+++ b/graphics/java/android/renderscript/Short4.java
@@ -28,6 +28,13 @@ public class Short4 {
public Short4() {
}
+ public Short4(short initX, short initY, short initZ, short initW) {
+ x = initX;
+ y = initY;
+ z = initZ;
+ w = initW;
+ }
+
public short x;
public short y;
public short z;
diff --git a/graphics/java/android/renderscript/Type.java b/graphics/java/android/renderscript/Type.java
index b39d2e4..f88af8b 100644
--- a/graphics/java/android/renderscript/Type.java
+++ b/graphics/java/android/renderscript/Type.java
@@ -46,12 +46,18 @@ public class Type extends BaseObj {
Element mElement;
public enum CubemapFace {
- POSITVE_X (0),
+ POSITIVE_X (0),
NEGATIVE_X (1),
- POSITVE_Y (2),
+ POSITIVE_Y (2),
NEGATIVE_Y (3),
- POSITVE_Z (4),
- NEGATIVE_Z (5);
+ POSITIVE_Z (4),
+ NEGATIVE_Z (5),
+ @Deprecated
+ POSITVE_X (0),
+ @Deprecated
+ POSITVE_Y (2),
+ @Deprecated
+ POSITVE_Z (4);
int mID;
CubemapFace(int id) {
diff --git a/graphics/java/com/android/internal/graphics/NativeUtils.java b/graphics/java/com/android/internal/graphics/NativeUtils.java
deleted file mode 100644
index c91b7d9..0000000
--- a/graphics/java/com/android/internal/graphics/NativeUtils.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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 com.android.internal.graphics;
-
-import android.graphics.Canvas;
-import android.graphics.Rect;
-
-public final class NativeUtils {
- /**
- * This class is uninstantiable.
- */
- private NativeUtils() {
- // This space intentionally left blank.
- }
-
- /**
- * Scroll a rectangular portion of a canvas.
- *
- * @param canvas the canvas to manipulate
- * @param src the source rectangle
- * @param dx horizontal offset
- * @param dy vertical offset
- */
- public static native boolean nativeScrollRect(Canvas canvas, Rect src,
- int dx, int dy);
-}