Home | History | Annotate | Download | only in graphics
      1 #include "GraphicsJNI.h"
      2 #include "Sk1DPathEffect.h"
      3 #include "SkCornerPathEffect.h"
      4 #include "SkDashPathEffect.h"
      5 #include "SkDiscretePathEffect.h"
      6 #include "SkPathEffect.h"
      7 #include "core_jni_helpers.h"
      8 
      9 #include <jni.h>
     10 
     11 class SkPathEffectGlue {
     12 public:
     13 
     14     static void destructor(JNIEnv* env, jobject, jlong effectHandle) {
     15         SkPathEffect* effect = reinterpret_cast<SkPathEffect*>(effectHandle);
     16         SkSafeUnref(effect);
     17     }
     18 
     19     static jlong Compose_constructor(JNIEnv* env, jobject,
     20                                      jlong outerHandle, jlong innerHandle) {
     21         SkPathEffect* outer = reinterpret_cast<SkPathEffect*>(outerHandle);
     22         SkPathEffect* inner = reinterpret_cast<SkPathEffect*>(innerHandle);
     23         SkPathEffect* effect = SkComposePathEffect::Create(outer, inner);
     24         return reinterpret_cast<jlong>(effect);
     25     }
     26 
     27     static jlong Sum_constructor(JNIEnv* env, jobject,
     28                                  jlong firstHandle, jlong secondHandle) {
     29         SkPathEffect* first = reinterpret_cast<SkPathEffect*>(firstHandle);
     30         SkPathEffect* second = reinterpret_cast<SkPathEffect*>(secondHandle);
     31         SkPathEffect* effect = SkSumPathEffect::Create(first, second);
     32         return reinterpret_cast<jlong>(effect);
     33     }
     34 
     35     static jlong Dash_constructor(JNIEnv* env, jobject,
     36                                       jfloatArray intervalArray, jfloat phase) {
     37         AutoJavaFloatArray autoInterval(env, intervalArray);
     38         int         count = autoInterval.length() & ~1;  // even number
     39 #ifdef SK_SCALAR_IS_FLOAT
     40         SkScalar*   intervals = autoInterval.ptr();
     41 #else
     42         #error Need to convert float array to SkScalar array before calling the following function.
     43 #endif
     44         SkPathEffect* effect = SkDashPathEffect::Create(intervals, count, phase);
     45         return reinterpret_cast<jlong>(effect);
     46     }
     47 
     48     static jlong OneD_constructor(JNIEnv* env, jobject,
     49                   jlong shapeHandle, jfloat advance, jfloat phase, jint style) {
     50         const SkPath* shape = reinterpret_cast<SkPath*>(shapeHandle);
     51         SkASSERT(shape != NULL);
     52         SkPathEffect* effect = SkPath1DPathEffect::Create(*shape, advance, phase,
     53                 (SkPath1DPathEffect::Style)style);
     54         return reinterpret_cast<jlong>(effect);
     55     }
     56 
     57     static jlong Corner_constructor(JNIEnv* env, jobject, jfloat radius){
     58         SkPathEffect* effect = SkCornerPathEffect::Create(radius);
     59         return reinterpret_cast<jlong>(effect);
     60     }
     61 
     62     static jlong Discrete_constructor(JNIEnv* env, jobject,
     63                                       jfloat length, jfloat deviation) {
     64         SkPathEffect* effect = SkDiscretePathEffect::Create(length, deviation);
     65         return reinterpret_cast<jlong>(effect);
     66     }
     67 
     68 };
     69 
     70 ////////////////////////////////////////////////////////////////////////////////////////////////////////
     71 
     72 static const JNINativeMethod gPathEffectMethods[] = {
     73     { "nativeDestructor", "(J)V", (void*)SkPathEffectGlue::destructor }
     74 };
     75 
     76 static const JNINativeMethod gComposePathEffectMethods[] = {
     77     { "nativeCreate", "(JJ)J", (void*)SkPathEffectGlue::Compose_constructor }
     78 };
     79 
     80 static const JNINativeMethod gSumPathEffectMethods[] = {
     81     { "nativeCreate", "(JJ)J", (void*)SkPathEffectGlue::Sum_constructor }
     82 };
     83 
     84 static const JNINativeMethod gDashPathEffectMethods[] = {
     85     { "nativeCreate", "([FF)J", (void*)SkPathEffectGlue::Dash_constructor }
     86 };
     87 
     88 static const JNINativeMethod gPathDashPathEffectMethods[] = {
     89     { "nativeCreate", "(JFFI)J", (void*)SkPathEffectGlue::OneD_constructor }
     90 };
     91 
     92 static const JNINativeMethod gCornerPathEffectMethods[] = {
     93     { "nativeCreate", "(F)J", (void*)SkPathEffectGlue::Corner_constructor }
     94 };
     95 
     96 static const JNINativeMethod gDiscretePathEffectMethods[] = {
     97     { "nativeCreate", "(FF)J", (void*)SkPathEffectGlue::Discrete_constructor }
     98 };
     99 
    100 int register_android_graphics_PathEffect(JNIEnv* env)
    101 {
    102     android::RegisterMethodsOrDie(env, "android/graphics/PathEffect", gPathEffectMethods,
    103                          NELEM(gPathEffectMethods));
    104     android::RegisterMethodsOrDie(env, "android/graphics/ComposePathEffect",
    105                                   gComposePathEffectMethods, NELEM(gComposePathEffectMethods));
    106     android::RegisterMethodsOrDie(env, "android/graphics/SumPathEffect", gSumPathEffectMethods,
    107                                   NELEM(gSumPathEffectMethods));
    108     android::RegisterMethodsOrDie(env, "android/graphics/DashPathEffect", gDashPathEffectMethods,
    109                                   NELEM(gDashPathEffectMethods));
    110     android::RegisterMethodsOrDie(env, "android/graphics/PathDashPathEffect",
    111                                   gPathDashPathEffectMethods, NELEM(gPathDashPathEffectMethods));
    112     android::RegisterMethodsOrDie(env, "android/graphics/CornerPathEffect",
    113                                   gCornerPathEffectMethods, NELEM(gCornerPathEffectMethods));
    114     android::RegisterMethodsOrDie(env, "android/graphics/DiscretePathEffect",
    115                                   gDiscretePathEffectMethods, NELEM(gDiscretePathEffectMethods));
    116 
    117     return 0;
    118 }
    119