diff options
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/java/android/graphics/Canvas.java | 27 | ||||
-rw-r--r-- | graphics/java/android/graphics/Paint.java | 163 | ||||
-rw-r--r-- | graphics/java/android/graphics/SurfaceTexture.java | 15 | ||||
-rw-r--r-- | graphics/java/android/graphics/drawable/BitmapDrawable.java | 92 | ||||
-rw-r--r-- | graphics/java/android/renderscript/BaseObj.java | 16 | ||||
-rw-r--r-- | graphics/java/android/renderscript/RenderScript.java | 17 | ||||
-rw-r--r-- | graphics/java/android/renderscript/ScriptC.java | 7 | ||||
-rw-r--r-- | graphics/jni/Android.mk | 2 | ||||
-rw-r--r-- | graphics/jni/android_renderscript_RenderScript.cpp | 54 |
9 files changed, 317 insertions, 76 deletions
diff --git a/graphics/java/android/graphics/Canvas.java b/graphics/java/android/graphics/Canvas.java index 965abe9..e493b18 100644 --- a/graphics/java/android/graphics/Canvas.java +++ b/graphics/java/android/graphics/Canvas.java @@ -1330,6 +1330,29 @@ public class Canvas { } /** + * Draw the glyphs, with origin at (x,y), using the specified paint. The + * origin is interpreted based on the Align setting in the paint. + * + * @param glyphs The glyphs to be drawn + * @param x The x-coordinate of the origin of the text being drawn + * @param y The y-coordinate of the origin of the text being drawn + * @param paint The paint used for the text (e.g. color, size, style) + * + * @hide + * + * Used only for BiDi / RTL Tests + */ + public void drawGlyphs(char[] glyphs, int index, int count, float x, float y, + Paint paint) { + if ((index | count | (index + count) | + (glyphs.length - index - count)) < 0) { + throw new IndexOutOfBoundsException(); + } + native_drawGlyphs(mNativeCanvas, glyphs, index, count, x, y, paint.mBidiFlags, + paint.mNativePaint); + } + + /** * Draw the text, with origin at (x,y), using the specified paint. The * origin is interpreted based on the Align setting in the paint. * @@ -1722,7 +1745,9 @@ public class Canvas { private static native void native_drawText(int nativeCanvas, String text, int start, int end, float x, float y, int flags, int paint); - + private static native void native_drawGlyphs(int nativeCanvas, char[] glyphs, + int index, int count, float x, + float y, int flags, int paint); private static native void native_drawTextRun(int nativeCanvas, String text, int start, int end, int contextStart, int contextEnd, float x, float y, int flags, int paint); diff --git a/graphics/java/android/graphics/Paint.java b/graphics/java/android/graphics/Paint.java index 0a23bae..0949beb 100644 --- a/graphics/java/android/graphics/Paint.java +++ b/graphics/java/android/graphics/Paint.java @@ -1455,6 +1455,43 @@ public class Paint { } /** + * Return the glypth 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 getTextGlypths(String text, int start, int end, int contextStart, int contextEnd, + int flags, char[] glyphs) { + 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(); + } + if (flags != DIRECTION_LTR && flags != DIRECTION_RTL) { + throw new IllegalArgumentException("unknown flags value: " + flags); + } + return native_getTextGlyphs(mNativePaint, text, start, end, contextStart, contextEnd, + flags, glyphs); + } + + /** * Convenience overload that takes a char array instead of a * String. * @@ -1497,6 +1534,48 @@ public class Paint { } /** + * Convenience overload that takes a char array instead of a + * String. + * + * @see #getTextRunAdvances(String, int, int, int, int, int, float[], int) + * @hide + */ + public float getTextRunAdvancesICU(char[] chars, int index, int count, + int contextIndex, int contextCount, int flags, float[] advances, + int advancesIndex) { + + if ((index | count | contextIndex | contextCount | advancesIndex + | (index - contextIndex) + | ((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 (!mHasCompatScaling) { + return native_getTextRunAdvancesICU(mNativePaint, chars, index, count, + contextIndex, contextCount, flags, advances, advancesIndex); + } + + final float oldSize = getTextSize(); + setTextSize(oldSize * mCompatScaling); + float res = native_getTextRunAdvancesICU(mNativePaint, chars, index, count, + contextIndex, contextCount, flags, advances, advancesIndex); + setTextSize(oldSize); + + if (advances != null) { + for (int i = advancesIndex, e = i + count; i < e; i++) { + advances[i] *= mInvCompatScaling; + } + } + return res * mInvCompatScaling; // assume errors are not significant + } + + /** * Convenience overload that takes a CharSequence instead of a * String. * @@ -1532,6 +1611,41 @@ public class Paint { } /** + * Convenience overload that takes a CharSequence instead of a + * String. + * + * @see #getTextRunAdvances(String, int, int, int, int, int, float[], int) + * @hide + */ + public float getTextRunAdvancesICU(CharSequence text, int start, int end, + int contextStart, int contextEnd, int flags, float[] advances, + int advancesIndex) { + + if (text instanceof String) { + return getTextRunAdvancesICU((String) text, start, end, + contextStart, contextEnd, flags, advances, advancesIndex); + } + if (text instanceof SpannedString || + text instanceof SpannableString) { + return getTextRunAdvancesICU(text.toString(), start, end, + contextStart, contextEnd, flags, advances, advancesIndex); + } + if (text instanceof GraphicsOperations) { + return ((GraphicsOperations) text).getTextRunAdvancesICU(start, end, + contextStart, contextEnd, flags, advances, advancesIndex, this); + } + + int contextLen = contextEnd - contextStart; + int len = end - start; + char[] buf = TemporaryBuffer.obtain(contextLen); + TextUtils.getChars(text, start, end, buf, 0); + float result = getTextRunAdvancesICU(buf, start - contextStart, len, + 0, contextLen, flags, advances, advancesIndex); + TemporaryBuffer.recycle(buf); + return result; + } + + /** * 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). @@ -1607,6 +1721,44 @@ public class Paint { } /** + * Temporary - DO NOT USE + * + * @hide + */ + public float getTextRunAdvancesICU(String text, int start, int end, int contextStart, + int contextEnd, int flags, float[] advances, int advancesIndex) { + + 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 (flags != DIRECTION_LTR && flags != DIRECTION_RTL) { + throw new IllegalArgumentException("unknown flags value: " + flags); + } + + if (!mHasCompatScaling) { + return native_getTextRunAdvancesICU(mNativePaint, text, start, end, + contextStart, contextEnd, flags, advances, advancesIndex); + } + + final float oldSize = getTextSize(); + setTextSize(oldSize * mCompatScaling); + float totalAdvance = native_getTextRunAdvances(mNativePaint, text, start, end, + contextStart, contextEnd, flags, advances, advancesIndex); + setTextSize(oldSize); + + if (advances != null) { + for (int i = advancesIndex, e = i + (end - start); i < e; i++) { + advances[i] *= mInvCompatScaling; + } + } + return totalAdvance * mInvCompatScaling; // assume errors are insignificant + } + + /** * Returns the next cursor position in the run. This avoids placing the * cursor between surrogates, between characters that form conjuncts, * between base characters and combining marks, or within a reordering @@ -1859,6 +2011,10 @@ 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); @@ -1866,6 +2022,13 @@ public class Paint { String text, int start, int end, int contextStart, int contextEnd, int flags, float[] advances, int advancesIndex); + private static native float native_getTextRunAdvancesICU(int native_object, + char[] text, int index, int count, int contextIndex, int contextCount, + int flags, float[] advances, int advancesIndex); + private static native float native_getTextRunAdvancesICU(int native_object, + String text, int start, int end, int contextStart, int contextEnd, + int flags, float[] advances, int advancesIndex); + private native int native_getTextRunCursor(int native_object, char[] text, int contextStart, int contextLength, int flags, int offset, int cursorOpt); private native int native_getTextRunCursor(int native_object, String text, diff --git a/graphics/java/android/graphics/SurfaceTexture.java b/graphics/java/android/graphics/SurfaceTexture.java index 970b207..cfae0c1 100644 --- a/graphics/java/android/graphics/SurfaceTexture.java +++ b/graphics/java/android/graphics/SurfaceTexture.java @@ -144,6 +144,20 @@ 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 guaranteed to be monotonically increasing. 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(); + } + protected void finalize() throws Throwable { try { nativeFinalize(); @@ -182,6 +196,7 @@ public class SurfaceTexture { private native void nativeInit(int texName, Object weakSelf); private native void nativeFinalize(); private native void nativeGetTransformMatrix(float[] mtx); + private native long nativeGetTimestamp(); private native void nativeUpdateTexImage(); /* diff --git a/graphics/java/android/graphics/drawable/BitmapDrawable.java b/graphics/java/android/graphics/drawable/BitmapDrawable.java index 2c09ddc..a278466 100644 --- a/graphics/java/android/graphics/drawable/BitmapDrawable.java +++ b/graphics/java/android/graphics/drawable/BitmapDrawable.java @@ -67,7 +67,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 +87,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 +128,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 +153,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 +162,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 +257,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 +280,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,19 +368,18 @@ 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); } @@ -335,7 +393,7 @@ public class BitmapDrawable extends Drawable { canvas.drawBitmap(bitmap, null, mDstRect, state.mPaint); } else { if (mApplyGravity) { - mDstRect.set(getBounds()); + copyBounds(mDstRect); mApplyGravity = false; } canvas.drawRect(mDstRect, state.mPaint); @@ -448,9 +506,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 +523,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; @@ -491,6 +551,6 @@ public class BitmapDrawable extends Drawable { } else { mTargetDensity = DisplayMetrics.DENSITY_DEFAULT; } - setBitmap(state.mBitmap); + setBitmap(state != null ? state.mBitmap : null); } } diff --git a/graphics/java/android/renderscript/BaseObj.java b/graphics/java/android/renderscript/BaseObj.java index 669beac..a17e735 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; @@ -75,11 +75,17 @@ class BaseObj { * @param name The name to assign to the object. */ public void setName(String name) { + if (name == null) { + throw new RSIllegalArgumentException( + "setName requires a string of non-zero length."); + } if(name.length() < 1) { - throw new RSIllegalArgumentException("setName does not accept a zero length string."); + throw new RSIllegalArgumentException( + "setName does not accept a zero length string."); } if(mName != null) { - throw new RSIllegalArgumentException("setName object already has a name."); + throw new RSIllegalArgumentException( + "setName object already has a name."); } try { @@ -106,9 +112,9 @@ class BaseObj { } /** - * destroy disconnects the object from the native object effectivly + * destroy disconnects the object from the native object effectively * rendering this java object dead. The primary use is to force immediate - * cleanup of resources when its believed the GC will not respond quickly + * cleanup of resources when it is believed the GC will not respond quickly * enough. */ synchronized public void destroy() { diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java index b51279a..f577532 100644 --- a/graphics/java/android/renderscript/RenderScript.java +++ b/graphics/java/android/renderscript/RenderScript.java @@ -457,20 +457,11 @@ public class RenderScript { rsnScriptSetVarObj(mContext, id, slot, val); } - native void rsnScriptCBegin(int con); - synchronized void nScriptCBegin() { + 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(); - rsnScriptCBegin(mContext); - } - native void rsnScriptCSetScript(int con, byte[] script, int offset, int length); - synchronized void nScriptCSetScript(byte[] script, int offset, 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); diff --git a/graphics/java/android/renderscript/ScriptC.java b/graphics/java/android/renderscript/ScriptC.java index 9445283..f865753 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 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/jni/Android.mk b/graphics/jni/Android.mk index 4c4a128..084f54a 100644 --- a/graphics/jni/Android.mk +++ b/graphics/jni/Android.mk @@ -19,7 +19,7 @@ LOCAL_SHARED_LIBRARIES := \ libskia \ libutils \ libui \ - libsurfaceflinger_client + libgui LOCAL_STATIC_LIBRARIES := diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp index 2afd74c..c7f4809 100644 --- a/graphics/jni/android_renderscript_RenderScript.cpp +++ b/graphics/jni/android_renderscript_RenderScript.cpp @@ -848,65 +848,51 @@ nScriptInvokeV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slo // ----------------------------------- -static void -nScriptCBegin(JNIEnv *_env, jobject _this, RsContext con) +static jint +nScriptCCreate(JNIEnv *_env, jobject _this, RsContext con, + jstring resName, jstring cacheDir, + jbyteArray scriptRef, jint length) { - LOG_API("nScriptCBegin, con(%p)", con); - rsScriptCBegin(con); -} + LOG_API("nScriptCCreate, con(%p)", con); + + AutoJavaStringToUTF8 resNameUTF(_env, resName); + AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir); + jint ret = 0; -static void -nScriptCSetScript(JNIEnv *_env, jobject _this, RsContext con, jbyteArray scriptRef, - jint offset, jint length) -{ - LOG_API("!!! nScriptCSetScript, con(%p)", con); jint _exception = 0; jint remaining; - jbyte* script_base = 0; jbyte* script_ptr; if (!scriptRef) { _exception = 1; //_env->ThrowNew(IAEClass, "script == null"); goto exit; } - if (offset < 0) { - _exception = 1; - //_env->ThrowNew(IAEClass, "offset < 0"); - goto exit; - } if (length < 0) { _exception = 1; //_env->ThrowNew(IAEClass, "length < 0"); goto exit; } - remaining = _env->GetArrayLength(scriptRef) - offset; + remaining = _env->GetArrayLength(scriptRef); if (remaining < length) { _exception = 1; //_env->ThrowNew(IAEClass, "length > script.length - offset"); goto exit; } - script_base = (jbyte *) + script_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0); - script_ptr = script_base + offset; - rsScriptCSetText(con, (const char *)script_ptr, length); + //rsScriptCSetText(con, (const char *)script_ptr, length); + + ret = (jint)rsScriptCCreate(con, resNameUTF.c_str(), cacheDirUTF.c_str(), + (const char *)script_ptr, length); exit: - if (script_base) { - _env->ReleasePrimitiveArrayCritical(scriptRef, script_base, + if (script_ptr) { + _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr, _exception ? JNI_ABORT: 0); } -} -static jint -nScriptCCreate(JNIEnv *_env, jobject _this, RsContext con, jstring packageName, jstring resName, jstring cacheDir) -{ - LOG_API("nScriptCCreate, con(%p)", con); - AutoJavaStringToUTF8 packageNameUTF(_env, packageName); - AutoJavaStringToUTF8 resNameUTF(_env, resName); - AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir); - jint i = (jint)rsScriptCCreate(con, packageNameUTF.c_str(), resNameUTF.c_str(), cacheDirUTF.c_str()); - return i; + return ret; } // --------------------------------------------------------------------------- @@ -1282,9 +1268,7 @@ static JNINativeMethod methods[] = { {"rsnScriptSetVarV", "(III[B)V", (void*)nScriptSetVarV }, {"rsnScriptSetVarObj", "(IIII)V", (void*)nScriptSetVarObj }, -{"rsnScriptCBegin", "(I)V", (void*)nScriptCBegin }, -{"rsnScriptCSetScript", "(I[BII)V", (void*)nScriptCSetScript }, -{"rsnScriptCCreate", "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)I", (void*)nScriptCCreate }, +{"rsnScriptCCreate", "(ILjava/lang/String;Ljava/lang/String;[BI)I", (void*)nScriptCCreate }, {"rsnProgramStoreBegin", "(III)V", (void*)nProgramStoreBegin }, {"rsnProgramStoreDepthFunc", "(II)V", (void*)nProgramStoreDepthFunc }, |