am 98002dfb: Merge "AArch64: Use long for pointers in graphics/PathMeasure"

* commit '98002dfb60a20caf62d6682659547c042a4a3342':
  AArch64: Use long for pointers in graphics/PathMeasure
This commit is contained in:
Narayan Kamath
2014-01-16 07:31:58 -08:00
committed by Android Git Automerger
2 changed files with 72 additions and 46 deletions

View File

@@ -52,11 +52,24 @@ namespace android {
class SkPathMeasureGlue { class SkPathMeasureGlue {
public: public:
static PathMeasurePair* create(JNIEnv* env, jobject clazz, const SkPath* path, jboolean forceClosed) { static jlong create(JNIEnv* env, jobject clazz, jlong pathHandle,
return path ? new PathMeasurePair(*path, forceClosed) : new PathMeasurePair; jboolean forceClosedHandle) {
const SkPath* path = reinterpret_cast<SkPath*>(pathHandle);
bool forceClosed = (forceClosedHandle == JNI_TRUE);
PathMeasurePair* pair;
if(path)
pair = new PathMeasurePair(*path, forceClosed);
else
pair = new PathMeasurePair;
return reinterpret_cast<jlong>(pair);
} }
static void setPath(JNIEnv* env, jobject clazz, PathMeasurePair* pair, const SkPath* path, jboolean forceClosed) { static void setPath(JNIEnv* env, jobject clazz, jlong pairHandle,
jlong pathHandle, jboolean forceClosedHandle) {
PathMeasurePair* pair = reinterpret_cast<PathMeasurePair*>(pairHandle);
const SkPath* path = reinterpret_cast<SkPath*>(pathHandle);
bool forceClosed = (forceClosedHandle == JNI_TRUE);
if (NULL == path) { if (NULL == path) {
pair->fPath.reset(); pair->fPath.reset();
} else { } else {
@@ -64,11 +77,12 @@ public:
} }
pair->fMeasure.setPath(&pair->fPath, forceClosed); pair->fMeasure.setPath(&pair->fPath, forceClosed);
} }
static jfloat getLength(JNIEnv* env, jobject clazz, PathMeasurePair* pair) { static jfloat getLength(JNIEnv* env, jobject clazz, jlong pairHandle) {
return SkScalarToFloat(pair->fMeasure.getLength()); PathMeasurePair* pair = reinterpret_cast<PathMeasurePair*>(pairHandle);
return static_cast<jfloat>(SkScalarToFloat(pair->fMeasure.getLength()));
} }
static void convertTwoElemFloatArray(JNIEnv* env, jfloatArray array, const SkScalar src[2]) { static void convertTwoElemFloatArray(JNIEnv* env, jfloatArray array, const SkScalar src[2]) {
AutoJavaFloatArray autoArray(env, array, 2); AutoJavaFloatArray autoArray(env, array, 2);
jfloat* ptr = autoArray.ptr(); jfloat* ptr = autoArray.ptr();
@@ -76,13 +90,14 @@ public:
ptr[1] = SkScalarToFloat(src[1]); ptr[1] = SkScalarToFloat(src[1]);
} }
static jboolean getPosTan(JNIEnv* env, jobject clazz, PathMeasurePair* pair, jfloat dist, jfloatArray pos, jfloatArray tan) { static jboolean getPosTan(JNIEnv* env, jobject clazz, jlong pairHandle, jfloat dist, jfloatArray pos, jfloatArray tan) {
PathMeasurePair* pair = reinterpret_cast<PathMeasurePair*>(pairHandle);
SkScalar tmpPos[2], tmpTan[2]; SkScalar tmpPos[2], tmpTan[2];
SkScalar* posPtr = pos ? tmpPos : NULL; SkScalar* posPtr = pos ? tmpPos : NULL;
SkScalar* tanPtr = tan ? tmpTan : NULL; SkScalar* tanPtr = tan ? tmpTan : NULL;
if (!pair->fMeasure.getPosTan(SkFloatToScalar(dist), (SkPoint*)posPtr, (SkVector*)tanPtr)) { if (!pair->fMeasure.getPosTan(SkFloatToScalar(dist), (SkPoint*)posPtr, (SkVector*)tanPtr)) {
return false; return JNI_FALSE;
} }
if (pos) { if (pos) {
@@ -91,42 +106,53 @@ public:
if (tan) { if (tan) {
convertTwoElemFloatArray(env, tan, tmpTan); convertTwoElemFloatArray(env, tan, tmpTan);
} }
return true; return JNI_TRUE;
} }
static jboolean getMatrix(JNIEnv* env, jobject clazz, PathMeasurePair* pair, jfloat dist, static jboolean getMatrix(JNIEnv* env, jobject clazz, jlong pairHandle, jfloat dist,
SkMatrix* matrix, int flags) { jlong matrixHandle, jint flags) {
return pair->fMeasure.getMatrix(SkFloatToScalar(dist), matrix, (SkPathMeasure::MatrixFlags)flags); PathMeasurePair* pair = reinterpret_cast<PathMeasurePair*>(pairHandle);
SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
bool result = pair->fMeasure.getMatrix(SkFloatToScalar(dist), matrix, (SkPathMeasure::MatrixFlags)flags);
return result ? JNI_TRUE : JNI_FALSE;
} }
static jboolean getSegment(JNIEnv* env, jobject clazz, PathMeasurePair* pair, jfloat startF, static jboolean getSegment(JNIEnv* env, jobject clazz, jlong pairHandle, jfloat startF,
jfloat stopF, SkPath* dst, jboolean startWithMoveTo) { jfloat stopF, jlong dstHandle, jboolean startWithMoveTo) {
return pair->fMeasure.getSegment(SkFloatToScalar(startF), SkFloatToScalar(stopF), dst, startWithMoveTo); PathMeasurePair* pair = reinterpret_cast<PathMeasurePair*>(pairHandle);
SkPath* dst = reinterpret_cast<SkPath*>(dstHandle);
bool result = pair->fMeasure.getSegment(SkFloatToScalar(startF), SkFloatToScalar(stopF), dst, startWithMoveTo);
return result ? JNI_TRUE : JNI_FALSE;
} }
static jboolean isClosed(JNIEnv* env, jobject clazz, PathMeasurePair* pair) { static jboolean isClosed(JNIEnv* env, jobject clazz, jlong pairHandle) {
return pair->fMeasure.isClosed(); PathMeasurePair* pair = reinterpret_cast<PathMeasurePair*>(pairHandle);
bool result = pair->fMeasure.isClosed();
return result ? JNI_TRUE : JNI_FALSE;
} }
static jboolean nextContour(JNIEnv* env, jobject clazz, PathMeasurePair* pair) { static jboolean nextContour(JNIEnv* env, jobject clazz, jlong pairHandle) {
return pair->fMeasure.nextContour(); PathMeasurePair* pair = reinterpret_cast<PathMeasurePair*>(pairHandle);
bool result = pair->fMeasure.nextContour();
return result ? JNI_TRUE : JNI_FALSE;
} }
static void destroy(JNIEnv* env, jobject clazz, PathMeasurePair* pair) { static void destroy(JNIEnv* env, jobject clazz, jlong pairHandle) {
PathMeasurePair* pair = reinterpret_cast<PathMeasurePair*>(pairHandle);
delete pair; delete pair;
} }
}; };
static JNINativeMethod methods[] = { static JNINativeMethod methods[] = {
{"native_create", "(IZ)I", (void*) SkPathMeasureGlue::create }, {"native_create", "(JZ)J", (void*) SkPathMeasureGlue::create },
{"native_setPath", "(IIZ)V", (void*) SkPathMeasureGlue::setPath }, {"native_setPath", "(JJZ)V", (void*) SkPathMeasureGlue::setPath },
{"native_getLength", "(I)F", (void*) SkPathMeasureGlue::getLength }, {"native_getLength", "(J)F", (void*) SkPathMeasureGlue::getLength },
{"native_getPosTan", "(IF[F[F)Z", (void*) SkPathMeasureGlue::getPosTan }, {"native_getPosTan", "(JF[F[F)Z", (void*) SkPathMeasureGlue::getPosTan },
{"native_getMatrix", "(IFII)Z", (void*) SkPathMeasureGlue::getMatrix }, {"native_getMatrix", "(JFJI)Z", (void*) SkPathMeasureGlue::getMatrix },
{"native_getSegment", "(IFFIZ)Z", (void*) SkPathMeasureGlue::getSegment }, {"native_getSegment", "(JFFJZ)Z", (void*) SkPathMeasureGlue::getSegment },
{"native_isClosed", "(I)Z", (void*) SkPathMeasureGlue::isClosed }, {"native_isClosed", "(J)Z", (void*) SkPathMeasureGlue::isClosed },
{"native_nextContour", "(I)Z", (void*) SkPathMeasureGlue::nextContour }, {"native_nextContour", "(J)Z", (void*) SkPathMeasureGlue::nextContour },
{"native_destroy", "(I)V", (void*) SkPathMeasureGlue::destroy } {"native_destroy", "(J)V", (void*) SkPathMeasureGlue::destroy }
}; };
int register_android_graphics_PathMeasure(JNIEnv* env) { int register_android_graphics_PathMeasure(JNIEnv* env) {

View File

@@ -138,16 +138,16 @@ public class PathMeasure {
native_destroy(native_instance); native_destroy(native_instance);
} }
private static native int native_create(int native_path, boolean forceClosed); private static native long native_create(long native_path, boolean forceClosed);
private static native void native_setPath(int native_instance, int native_path, boolean forceClosed); private static native void native_setPath(long native_instance, long native_path, boolean forceClosed);
private static native float native_getLength(int native_instance); private static native float native_getLength(long native_instance);
private static native boolean native_getPosTan(int native_instance, float distance, float pos[], float tan[]); private static native boolean native_getPosTan(long native_instance, float distance, float pos[], float tan[]);
private static native boolean native_getMatrix(int native_instance, float distance, int native_matrix, int flags); private static native boolean native_getMatrix(long native_instance, float distance, long native_matrix, int flags);
private static native boolean native_getSegment(int native_instance, float startD, float stopD, int native_path, boolean startWithMoveTo); private static native boolean native_getSegment(long native_instance, float startD, float stopD, long native_path, boolean startWithMoveTo);
private static native boolean native_isClosed(int native_instance); private static native boolean native_isClosed(long native_instance);
private static native boolean native_nextContour(int native_instance); private static native boolean native_nextContour(long native_instance);
private static native void native_destroy(int native_instance); private static native void native_destroy(long native_instance);
/* package */private final int native_instance; /* package */private final long native_instance;
} }